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

Hello,
I'm using HTTP::Request::Common to send POST requests, unfortunatly the remote host field separator is not a & as usual but a \r\n (0d0a in hexadecimal).
How can I do ?
my %params= ('page' => 28, 'index' => 36); my $request = POST 'http://example.org', \%params; $mech->request($request); #send with Mechanize
When capture with wireshark :
Text based data
page=28&index=36
But the remote host expected
Text based data
page=28
index=36

Can I specify the field separator ? If not what can I do ?

Replies are listed 'Best First'.
Re: HTTP::Request::Common : Specify POST fields separators ?
by merlyn (Sage) on Jan 04, 2010 at 04:27 UTC
    If that server expects that, it's not really looking for HTTP form data. You'll have to construct a body manually.

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

      I understand, but the separator is still & and not \r\n

        So, generate your own request body, as you were told. What you want is not HTTP, even if it nearly looks the same and you will probably be able to abuse HTTP tools to generate your custom request. You could start by generating a standard HTTP request, storing that into a variable, replace all "&" inside the body with newlines, and then sending that modified request over the wire. The very first reply looks like a good start point.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: HTTP::Request::Common : Specify POST fields separators ?
by Anonymous Monk on Jan 04, 2010 at 03:47 UTC
    You need to learn your HTTP terminology
    #!/usr/bin/perl -- use strict; use warnings; use HTTP::Request::Common qw' POST '; my %params= ('page' => 28, 'index' => 36); print POST('http://example.org', \%params)->as_string,"\n\n"; print POST('http://example.org', { %params , qw' Content-Type form-dat +a ', } )->as_string; __END__ POST http://example.org Content-Length: 16 Content-Type: application/x-www-form-urlencoded index=36&page=28 POST http://example.org Content-Length: 39 Content-Type: application/x-www-form-urlencoded index=36&page=28&Content-Type=form-data
    The purpose of WWW::Mechanize is to avoid having to bother with these details.
      You got confused there, headers come after params
      #!/usr/bin/perl -- use strict; use warnings; use HTTP::Request::Common qw' POST '; my %params= ('page' => 28, 'index' => 36); print POST('http://example.org', \%params , qw' Content-Type form-data + ', )->as_string; __END__ POST http://example.org Content-Length: 132 Content-Type: multipart/form-data; boundary=xYzZY --xYzZY Content-Disposition: form-data; name="index" 36 --xYzZY Content-Disposition: form-data; name="page" 28 --xYzZY--
      That still doesn't help the OP with his custom protocol