ilauder has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to post to an HTTPS script (i.e. PayPal's payment system) and I'm using the LWP::browser->post function. The problem is post() seems to be encoding the name/value pairs and PayPal's system needs to receive the data unencoded. Is there a way to configure the post() function to not do any data encoding? Or is there another LWP function I can use to post the data that sends the data unencoded?

Replies are listed 'Best First'.
Re: LWP::browser->post encoding data
by moritz (Cardinal) on Jul 16, 2009 at 06:58 UTC
    What kind of encoding are you talking about? Character encodings (like UTF-8, Latin-1), or some kind of escaping mechanism?

    Anyway, I'd like to point out that there are modules for interacting with PayPal on CPAN, for example Business::PayPal::API and others.

    For general web automation stuff WWW::Mechanize is pretty neat.

      I would prefer to get LWP->browser->post to just stop url encoding the data values since I already have a working system to communicate with PayPal. The code is basic enough you don't really need another API on top of it like the PayPal library. If its a simple header or configuration function parameter I can set in the code setting up the post call would solve all my problems and would be the easiest solution.

      Here is what is happening:

      My code is passing in the the cancel and return urls unencoded, and when PayPal gets them they are encoded like below which then generates invalid url errors:

      TRXTYPE=S&TENDER=P&ACTION=S&PWD=2XXXXX1&USER=ilxxxer&VENDOR=ilxxxer&PARTNER=Verisign &CANCELURL=http%3A%2F%2Fwww.proposalkit.com &RETURNURL=http%3A%2F%2Fwww.proposalkit.com&AMT=42.00

      The code to send the data to PayPal is:

      $host = 'https://pilot-payflowpro.paypal.com'; @parm_list = ('TRXTYPE' => 'S', 'TENDER' => 'P', 'ACTION' => 'S', 'PWD' => $verisign_pwd, 'USER' => $verisign_usr, 'VENDOR' => $verisign_usr, 'PARTNER' => $verisign_prt, 'CANCELURL' => 'http://www.proposalkit.com', 'RETURNURL' => 'http://www.proposalkit.com', 'AMT' => '42.00'); @pf_headers = ('Content-Type' => 'text/namevalue'); my $browser = LWP::UserAgent->new(); if ($browser ne null) { $browser->timeout(90); $browser->agent('Cyber Sea Server'); my $response = $browser->post($host, [ @parm_list ], @pf_headers); }


      So I'm trying to find out if there is another setting I can put in the @pf_headers array or another $browser function that will make the post function not alter the data values in the @parm_list array.
        Please show the HTTP request you would like to send.