Phoenix.pm: LWP POST problems

Eden Li eden.li at asu.edu
Thu May 6 17:56:11 CDT 2004


According to LWP::UserAgent (and HTTP::Request::Common) docs, it appears 
that the quoted field does in fact get quoted correctly.  Have you tried 
using a web browser to input these values yourself?  It's possible curl 
is doing something strange with that % sign that you may not know about.

Here's an excerpt from HTTP::Request::Common docs (which is used by 
LWP::UserAgent)

   POST 'http://www.perl.org/survey.cgi',
        [ name   => 'Gisle Aas',
          email  => 'gisle at aas.no',
          gender => 'M',
          born   => '1964',
          perc   => '3%',
        ];

This will create a HTTP::Request object that looks like this:

   POST http://www.perl.org/survey.cgi
   Content-Length: 66
   Content-Type: application/x-www-form-urlencoded

   name=Gisle%20Aas&email=gisle%40aas.no&gender=M&born=1964&perc=3%25

Hope this helps...

eden

Matt Alexander wrote:
> I'm trying to post a URL-encoded character as part of the input to a
> website using LWP.  Here's a code example:
> 
> $browser = LWP::UserAgent->new();
> %formvars = ('somevar' => '%FC');
> $response = $browser->post($url, \%formvars);
> 
> When I run the code above I get a message from the CGI script on the
> server saying that '%' can't be used in the input field.  It works fine,
> however, when I post an ASCII character that doesn't need to be encoded.
> 
> Using curl, I can post to the server and get the desired results:
> 
> curl http://somewebsite.com -d somevar="%FC"
> 
> Any suggestions on how to get LWP to work the same as curl?
> Thanks,
> ~M



More information about the Phoenix-pm mailing list