Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

LWP 400 Bad Request on POST

by dsb (Chaplain)
on Nov 12, 2013 at 20:18 UTC ( [id://1062263]=perlquestion: print w/replies, xml ) Need Help??

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

Hello there.

I'm running into a wall (or more likely, a proxy) while trying to connect to a wsdl service via web call. I suspect the company proxy is not handling the request properly but I'm not sure how to help it along.

I'd like to avoid using company specific info, so the below URLs will not work. But know that when I request the specified URL from a browser, I get back a proper XML response. From the script, I get a 400 bad request error.

use strict; use LWP::UserAgent; my $g = LWP::UserAgent->new(show_progress => 1); $g->proxy(['http','ftp','https'], 'http://proxy.company.com:8080'); my $gr = HTTP::Request->new(POST => 'https://remote.othercomp.com/Sess +ionManagement/PublicSessionManagementService.svc?wsdl'); $gr->header('Content-Length' => '0'); my $gs = $g->request($gr); print $gs->status_line, "\n"; print $gs->content, "------- end content -------\n";
Results:
** POST https://wsnet.sendwordnow.com/SessionManagement/2010/05/Public +SessionManagementService.svc?wsdl ==> 400 Bad Request (1s) 400 Bad Request ------- end content -------
I've tried doing a normal GET request to Google.com and gotten back a good response and the appropriate content.

any help is much appreciated.


dsb
This @ISA my( $cool ) %SIG

Replies are listed 'Best First'.
Re: LWP 400 Bad Request on POST
by BrowserUk (Patriarch) on Nov 12, 2013 at 20:48 UTC

    This works for me:

    use LWP::Simple;; $c = get 'https://wsnet.sendwordnow.com/SessionManagement/2010/05/Publ +icSessionManagementService.svc?wsdl';; print $c;; <?xml version="1.0" encoding="utf-8"?><wsdl:definitions name="PublicSe +ssionManagementService" targetNamespace="http://tempuri.org/" ...

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      $c is undef when I try that. I'm guessing the proxy is screwing with the request somehow.


      dsb
      This @ISA my( $cool ) %SIG

        Open a local port. Send the same request (from your browser) a) to that local port directly (temporarily disabling the proxy); b) and via the proxy. Compare the requests received.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: LWP 400 Bad Request on POST
by ig (Vicar) on Nov 13, 2013 at 06:36 UTC

    My first preference would be to have a look at the proxy server configuration and logs.

    If I can't do that, I occasionally use Wireshark to inspect what is going over the wire and compare what the browser and script do.

      Wireshark was a big help, thank you. Ultimately the problem persists, but it's good to know (or be mostly sure anyway) where the problem is.

      dsb
      This @ISA my( $cool ) %SIG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1062263]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-16 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found