Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Can't get '+' character to appear in a POST request.

by oldwarrior32 (Sexton)
on Apr 22, 2013 at 22:39 UTC ( #1029990=perlquestion: print w/replies, xml ) Need Help??
oldwarrior32 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks. I apologize to ask such simple question for you.

I have the following script section:

$response = $session->post(' +o?reportID=91', Content => [vmReportType=>'', deviceId=>'', perVM=>'', category=>'0', bview=>'All', showType=>'1', top=>'10', time=>'custom', timeWindow=>'0-24', startTime=>'2013-04-21', startHour=>'19', endTime=>'2013-04-22', endHour=>'7', show=>'Show+Report']);

The problem is with the line 'show=>'Show+Report'. I made a packet capture using Wireshark, when I make a request from a webpage. In the packet capture I see the line 'Show+Report', as the parameter for the 'show' variable. However, when I simulate the request using the LWP::UserAgent module, and with the code above, I see the line changed: 'Show%2BReport'.

I want to send the '+' sign as is. I tried escaping with URI::Escape, but doesn't work

my $plus = '%2B'; show=>'Show'.uri_escape($plus).'Report'


my $plus = '+'; show=>'Show'.uri_escape($plus).'Report'

I tried with the uri_unescape function either with no luck

The change above gives me more hexadecimal characters

How do I escape the plus sign, inside a Post request using LWP::UserAgent?

Thanks for any help!

Replies are listed 'Best First'.
Re: Can't get '+' character to appear in a POST request.
by Anonymous Monk on Apr 23, 2013 at 01:50 UTC

    I want to send the '+' sign as is.

    No you don't, you want a space

    One way to encode space is as +, another way is as %20

      Thanks! I just put an space, instead of the plus sign in the code, and now I see the plus sign in the packet capture.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1029990]
Approved by kcott
[GotToBTru]: I've got a program with an if ... or ... statement with 80 clauses
[stevieb]: 80 clauses? dispatch table?
[GotToBTru]: no, lookup
[stevieb]: no, I mean have you considered using a dispatch table. an 80 condition if/else is huge :)
[GotToBTru]: that is how this should have been done, no question
[GotToBTru]: probably back when there were 5 or so clauses

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2017-06-22 13:00 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.