Do you mean HTTP::Request::Common will do the url_encode stuff automatically? Thanks Charles.


On 2013-7-25 18:30, Charles DeRykus wrote:
On 7/25/2013 12:57 AM, Feng He wrote:
Would LWP::UserAgent call the url_encode() method from URL::Encode
automatically for the posted content?


  use LWP::UserAgent;
  $ua = LWP::UserAgent->new;

  my $req = HTTP::Request->new(
      POST => 'http://rt.cpan.org/Public/Dist/Display.html');
  $req->content_type('application/x-www-form-urlencoded');
  $req->content('Status=Active&Name=libwww-perl');

  my $res = $ua->request($req);
  print $res->as_string;

If I recall correctly, no it won't.  And,  you can confirm that by
examining:

         $req->as_string;


Probably the easiest way to do this is with HTTP::Request::Common which
will handle escaping the form parameters for you, eg,


    use HTTP::Request::Common;
    use LWP::UserAgent;

    $ua->request( POST 'http://rt.cpan.org/Public/Dist/Display.html'
                      [ Status => ..., Name=>... ] );




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to