Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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", "https://asite.com:443/sub/create_user.cgi 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?
Thanks

Comment on Error reading Request
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', 'https://asite.com:443/sub/create_user.cgi', 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 'https://asite.com:443/sub/create_user.cgi', Content => '<userCreate>John.Doe</userCreate>', );

        --k.


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2014-09-20 15:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls