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

Greetings!

I have a Perl-based client using LWP to talk to a C# .NET server (I control the code on both sides). When the client does a POST, and everything is fine on the server, I get an HTTP 200 (all is good). When an exception is thrown on the server, I always get back an HTTP 400 (bad request) and nothing else about the problem.

I have used the command line utility CURL to POST to the server and that client gets back the error details from the server every time, so I have to assume that there is something about LWP or how it is configured that is masking the true error.

Does anyone have insight into this?

When I get back at work tomorrow, I'll post some code.

  • Comment on LWP and server-side exception propogation

Replies are listed 'Best First'.
Re: LWP and server-side exception propogation
by Anonymous Monk on Oct 08, 2009 at 00:54 UTC
    When an exception is thrown on the server, I always get back an HTTP 400 (bad request) and nothing else about the problem.

    No, you get back a HTTP::Response object, you should print $resp->dump;

      Yeah, I had it under a graphical debugger (from ActiveState's PDK) and saw the dump there. There was nothing showing anything but the 400.

      I originally thought it might be a server configuration issue until I saw the desired error details shown by the CURL client tool.

        One difference between LWP and curl is the User-Agent header in the request. Some servers and server-side applications look at that header (stupid idea, as the client can fake any user agent) and try to block some user agents (more stupid), either using a blacklist of "evil" ones or a whitelist of "good" ones (even more stupid).

        I don't think your code behaves like this, but perhaps a library you use on the server side has this nonsense behaviour. Try sending the request from LWP with curl's User-Agent header. If that works, look at your code, the library documentations for the server side, and finally the web server configuration and documentation.

        As a side note, I don't generally trust debuggers and rich IDEs. Try adding $response->dump() to your client code. Note that this method behaves like print $response->dump() when called in void context. So, if you want the dump on STDERR or in a log file, call it in a non-void context and write out the dump manually.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        I originally thought it might be a server configuration issue until I saw the desired error details shown by the CURL client tool.

        Right, sure, absolutely, whatever you say :D