Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

jdavidb
  (email not shown publicly)
http://voiceofjohn.blogspot.com/

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Thursday May 08, 2008
03:10 PM

Java: Gotta POST

[ #36360 ]

I'm interacting with a .NET (I think) webservice, and I have to create a URL-encoded POST request. Conceptually, no biggie: I've used CGI.pm for years and understand the concept well. (Better than ASP.NET webservices, apparently, as I am aware that semicolon is a valid substitute for ? as a variable separator and ASP.NET webservices are not.) But of course I'm doing this from Java, so there's the extra work of looking up the right library^Wseventeen libraries to use.

Except that the libraries don't seem to fully cover this. Thankfully there's a URLEncoder class, or might just crawl away and die, but there's nothing to create the whole POST request for me from a HashMap or something. I have to generate all the headers myself, including the content-length, and I have to encode each parameter individually and glue them all together myself with = and ;. I mean = and &.

Annoying. So I guess I'll subclass HashMap myself and do it that way. Fun little exercise, I suppose, but this should be there for me.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Don't use a subclass of HashMap. Write a class that implements Map, and keep a HashMap internally. That'll be much more flexible.
    • It's a little late. :)

      But really, I don't see how I'm more flexible for implementing Map than simply subclassing HashMap. That just seems like a lot of trouble writing delegates methods that would otherwise just be there if I subclass. It's probably because Perl is the screwdriver with which I attempt to hammer every nail, and the Perl version of hashes as one of the three fundamental data structures is indelibly marked on my mind.

      I suppose it makes things easier if ever I want to use some other struc

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers