Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

How can I stop a POST from url encoding.

by dwatson06 (Friar)
on Jun 28, 2002 at 20:48 UTC ( #178137=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 create a POST to a CGI script on another server. I am connecting to the server but it can not route the POST because it thinks that 'create_user.cgi' is 'create_user.cgi%20HTTP/1.0'. Also the content is getting url encoded <user>john@doe</user> as %3Cuser%3john%4doe%3enduser%3. I have tried using apostrophe over double quotes, the /, /s, etc... HTTP/1.0 must be passed to the server. Is there a way to force characters in?

$req = POST ' HTTP/1.0' , [ '&lt;user&gt;john@doe&lt;enduser&gt;' ]; print $req->as_string();
Thank you

2002-06-29 Edit by Corion : Moved from QandA, added formatting

Replies are listed 'Best First'.
Re: How can I stop a POST from url encoding.
by amphiplex (Monk) on Jun 29, 2002 at 11:20 UTC
    There are two issues here:
    • changing the http-version: The only way to do this that I have found is to set an Environment Variable
    • url-encoding: Just set the content with the content method provided by HTTP::Request

    Here is a small example that should do what you wanted:
    use strict; sub BEGIN { # force HTTP version to 1.0 $ENV{PERL_LWP_USE_HTTP_10} = "1"; } use LWP::UserAgent; use HTTP::Request::Common qw(POST); my $ua = new LWP::UserAgent (); my $req = POST 'http://localhost:4443/'; $req->content("<user>john\@doe</user>"); print $req->as_string; my $response = $ua->request($req); print $response->as_string;
    Update:Please be careful when using the "trick" with the Environmant Vaiable, as I have seen it in the code not in any documentation. So I believe that this is an inofficial feature, which could disappear with a new version of LWP.
    ---- kurt
Re: How can I stop a POST from url encoding.
by Aristotle (Chancellor) on Jun 29, 2002 at 11:00 UTC
    It can't work that way. I've flipped through the docs, but there seems to be no way to adjust the HTTP version. Looks like you have to fiddle in the innards of the LWP:: modules somewhere - &LWP::Protocol::http::request() seems to be where it's at. That, or &HTTP::Request::as_string() maybe. Or maybe somewhere else - I didn't look for very long.

    Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://178137]
Approved by rob_au
[marinersk]: sub newtest{my $expected_result = &target('foo'); my $actual_result = &target('foo'); if ($actual_result eq $expected_result) { &tdd_success(); } else { &tdd_fail(); } } # Test works after three years!
[choroba]: or nobody bothered...
[choroba]: The problem was bigger, as the test tried to call a method that didn't exist anymore
[marinersk]: :: ducking ::
[choroba]: because, someone renamed the method, but didn't notice it was used in the test, as the test was skipped
[marinersk]: Well, if the method doesn't exist, it would be hard to pass the test.
[choroba]: later, someone removed the new method, as all its usage places were safe, but didn't notice the test still used the old name
[choroba]: fortunately, it wasn't that hard to replace the method and fix a few remaining failures due to the changes we did to the codebase over the years
[marinersk]: choroba Sounds like a process improvement opportunity; tests may not all need to be run, but they should all be compiled with perl -c before check-in/promotion happens.
[choroba]: so, now I have the test, so I can start making changes in the code. Back to the original ticket, yay!

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2017-05-25 15:10 GMT
Find Nodes?
    Voting Booth?