in reply to LWP: transfer from Python to Perl

Thanks hipo,haj for your comments !

both code fragments are just fragments. The use commands I have at the beginning. Also the # sign was comming from trying different things out.

"does not work" is indeed not specific! Sorry for that ! The issue is that the python version works fine. The server gives back the requested data. In the perl version the server response with an Error 500 Internal Server Error. That mens that something must be different in the two sended POSTs.

When the line #$request->content($json_data) is commented out, than the server response an error 411 Length Required

What would also help: Can I log what was exactly sent in both cases, to be able to compare all sent data ?

Replies are listed 'Best First'.
Re^2: LWP: transfer from Python to Perl
by hippo (Archbishop) on Jan 10, 2018 at 15:40 UTC
    In the perl version the server response with an Error 500 Internal Server Error.

    Without further details the best guess would be that you have not set the Content-Type header correctly (or at all). It also looks like you are attempting to set headers with leading underscores in the key. That's not going to work either.

    Can I log what was exactly sent

    Listen on the wire; see tcpdump for that. Otherwise use $request->dump.

      Hi hippo,

      Sorry for these basic questions. Thats one of my first web programs. I logged the packet:. I see some differences, but I can not really charge if this can be the rootcause: (first good one, second problem one)
      Accept-Encoding: identity Content-Type: application/x-www-form-urlencoded Content-Length: 2 User-Agent: Python-urllib/3.6 __Atts: 2018 __Ath: FnD= __Atcrv: 88 Connection: close TE: deflate,gzip;q=0.3 Connection: TE, close User-Agent: libwww-perl/6.26 __atcrv: 88 __ath: FnD= __atts: 2018 Content-Length: 2

        This confirms what I suspected in my previous post - namely that you have not set the Content-Type header. Most web servers will depend on this to be set correctly in the requests they receive.

      For the header key I saw also when I Dumper($request) the '_' were changed to '-'. (use Data::Dumper qw(Dumper); ) So I tried to write the header directly in the request structure.
      ${${$request}{'_headers'}}{'__atts'}=$ajax_atts; ${${$request}{'_headers'}}{'__ath'}=$ajax_ath; ${${$request}{'_headers'}}{'__atcrv'}=$ajax_atcrv2; print Dumper($request)
      Now the '_' are unchanged, but still error 500.

        You can preserve the underscores with a colon

        $request->header( ':__Atts' => $ajax_atts, ':__Ath' => $ajax_ath, ':__Atcrv'=> $ajax_atcrv);

        see NON-CANONICALIZED FIELD NAMES in HTTP::Headers

        poj