Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Error reading Request

by dwatson06 (Friar)
on Jun 26, 2002 at 19:22 UTC ( #177494=perlquestion: print w/replies, xml ) Need Help??
dwatson06 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to pass information (Post) to a CGI script on another server. When I send a request, that server is giving a '404 Not Found' error.
It appears that on the server I am sending the request to, the line feed and carriage return are read as a literal string value and not parsed properly. The server gets the Request and is not parsing the /r/n.

use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request("POST", " HTTP/1.0\r\nContent-type:application/x-www-form-urlencoded\r\nContent-length:33\r\n\r\n<userCreate>John.Doe</userCreate>\r\n\r\n");
my $res = $ua->request($req);
Is there another way to pass a carriage return & line feed?
Am I missing a value in the handshake?

Replies are listed 'Best First'.
Re: Error reading Request
by Kanji (Parson) on Jun 26, 2002 at 19:49 UTC

    HTTP::Request->new expects it's second argument to be an URL, and so is probably escaping your string in an attempt to Do The Right Thing(tm).

    Instead, you want to use the optional third (headers) and fourth (content) arguments...

    my $req = HTTP::Request->new( 'POST', '', HTTP::Headers->new( Content_Type => 'application/x-www-form-urlencoded', Content_Length => 33, ), '<userCreate>John.Doe</userCreate>', );

    Although I personally find the shortcut functions in HTTP::Request::Common a lot more readable...

    my $req = POST '', Content => '<userCreate>John.Doe</userCreate>', );


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://177494]
Approved by vladb
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-05-25 15:24 GMT
Find Nodes?
    Voting Booth?