andyford has asked for the wisdom of the Perl Monks concerning the following question:

From LiveHTTPHeaders, I get that I need to do this:
GET https://somesite.com/foo/bar;jsessionid=0001CxASgCKob1dDFdsSDSDF:- +1?requestor=AGE&doctype=Statement&docid=NTczMyT1LTc5LTMtMS0wLQ%3D%3D& +token=df99a322563f
So I coded it up like so:
$url = URI->new("https://somesite.com/foo/bar;jsessionid=$jsession +Id"); $url->query_form( requestor => 'AGE', doctype => 'Statement', docid => $docid, token => $token, ); $response = $agent->get($url);
But I get "400 Bad Request".

The above code is the last step of a five stage process where I log in, navigate, collect cookies and headers and whatnot to fill in the variables.

I have verified that all the previous steps work great with nice return codes and the HTML content is just as it should be, matching what I get with a browser.

Since you can't really test your answers, wild guesses are OK in this thread :)

UPDATE:
Amazing Fact: The HTML error page that is returned with my 400 actually contains a URL. The error page says that the URL is no good, but if I paste it into a web browser location line, it works and pulls the pdf file down.

Replies are listed 'Best First'.
Re: LWP GET: '400 Bad Request'
by derby (Abbot) on Jun 29, 2006 at 18:36 UTC

    I'd try

    $url = URI->new("https://somesite.com/foo/bar"); $url->query_form( jsessionid => $jsessionId, requestor => 'AGE', doctype => 'Statement', docid => $docid, token => $token, ); $response = $agent->get($url);

    -derby
      No, thanks for the thought, but the semicolon-jsession id is definately correct.
Re: LWP GET: '400 Bad Request'
by samtregar (Abbot) on Jun 29, 2006 at 18:06 UTC
    I'd hook up a sniffer (ethereal is my favorite) and see what's actually happening between server and client. The server thinks your request is invalid and it'll help you to understand why if you can see the actual request.

    If you're not comfortable with a sniffer then consider this a great opportunity - your time spent debugging networking problems will go way down once you are!

    -sam

      I like ethereal, too. I am one of the developers. The main developers are now working on wireshark, which started with the ethereal code base. Check the wireshark site for more information.
Re: LWP GET: '400 Bad Request'
by Anonymous Monk on Aug 08, 2006 at 03:39 UTC
    The first thing I try when a web request fails for no apparent reason is spoof a useragent like Mozilla/5.0, because a lot of sites block the default agent of popular Perl modules like lwp.
Re: LWP GET: '400 Bad Request'
by Anonymous Monk on Aug 08, 2006 at 03:40 UTC
    You might also try POST instead of GET.