Search code examples
perlhttprequestlwp

HTTP::Request and literal %2B


I am making a script that POST some XML to another server but I have problems with a plus singn (+). Here is my code:

#!/usr/bin/perl

use strict;
use warnings;
use LWP::UserAgent;

my $XML = qq|
<?xml version="1.0" encoding="UTF-8"?>
<ServiceAddRQ>
<Service code="Ws%2BsuHG7Xqk01RaIxm2L/w1L">
<ContractList>
<Contract>
<Name>CGW-TODOSB2B</Name>
</Contract>
</ContractList>
</Service>
</ServiceAddRQ>
|;

utf8::encode($XML);


my $ua = LWP::UserAgent->new;
$ua->timeout(120);

my $ret = HTTP::Request->new('POST', $XMLurl);
$ret->content_type('application/x-www-form-urlencoded'); 
$ret->content("xml_request=$XML");

my $response = $ua->request($ret);

As you can see in the attribute code the value string have %2B and the other server recive the value "Ws+suHG7Xqk01RaIxm2L/w1L".

How ca i send %2B literal.

Thanks in advance

Welch


Solution

  • You need to escape all unsafe characters in the content like this:

    use URI::Escape;
    $ret->content("xml_request=".uri_escape($XML));