Different POST encoding format

  • Thread starter David Joseph Bonnici
  • Start date
D

David Joseph Bonnici

Hi I was experimenting with perl, on the POST method. I am using
LWP::UserAgent

$response = $browser->post( $url,
[ 'first name' => 'John',
'last name' => 'Doe',
'lastandfirst' => 'John Doe',
] );

If I post, the data is sent something like this
"&first+name=John&last+name=Doe&lastandfirst=John+Doe"

I would like the post to be something enocoded like so (dont ask me why!)
&first%20name=John&last%20name=Doe&lastandfirst=John&20Doe

How do I do it (or what parameter do I need to modify).

This is sending me crazy.

David
 
G

Gunnar Hjalmarsson

David said:
Hi I was experimenting with perl, on the POST method. I am using
LWP::UserAgent

$response = $browser->post( $url,
[ 'first name' => 'John',
'last name' => 'Doe',
'lastandfirst' => 'John Doe',
] );

If I post, the data is sent something like this
"&first+name=John&last+name=Doe&lastandfirst=John+Doe"

I would like the post to be something enocoded like so (dont ask me why!)
&first%20name=John&last%20name=Doe&lastandfirst=John&20Doe

Why?
 
P

Peter Wyzl

: Hi I was experimenting with perl, on the POST method. I am using
: LWP::UserAgent
:
: $response = $browser->post( $url,
: [ 'first name' => 'John',
: 'last name' => 'Doe',
: 'lastandfirst' => 'John Doe',
: ] );
:
: If I post, the data is sent something like this
: "&first+name=John&last+name=Doe&lastandfirst=John+Doe"
:
: I would like the post to be something enocoded like so (dont ask me why!)
: &first%20name=John&last%20name=Doe&lastandfirst=John&20Doe
:
: How do I do it (or what parameter do I need to modify).
:
: This is sending me crazy.

So url encode your names and values before you post them. But it does beg
the question 'why'. However, I sense an 'X - Y' question.

P
 
A

Alan J. Flavell

Hi I was experimenting with perl, on the POST method. I am using
LWP::UserAgent

$response = $browser->post( $url,
[ 'first name' => 'John',
'last name' => 'Doe',
'lastandfirst' => 'John Doe',
] );

If I post, the data is sent something like this
"&first+name=John&last+name=Doe&lastandfirst=John+Doe"

Check the definition of the form url encoding format. This is the
correct submission.
I would like the post to be something enocoded like so (dont ask me why!)
&first%20name=John&last%20name=Doe&lastandfirst=John&20Doe

Stop wanting that. It's not a defined form submission format.
You'd be creating a completely pointless incompatibility with web
interworking specifications.
This is sending me crazy.

Often happens when one wants the wrong thing. This has nothing to do
with Perl, by the way.
 
D

David Joseph Bonnici

Thanks for coming back to me, both of you. I was in the mean time doing
some reasearch, and I think I found it.

I think that I have to do the escaping on the single pieces of the data
using URI:Escape

for example
.....
use URI::Escape;
print uri_escape("David sleeps more 10% than other people do");
.....

giving
David%20sleeps%20more%2010%25%20than%20other%20people%20do

I let you know

David
 
D

David Joseph Bonnici

Sorry Alan, you are wrong is saying so. I want to do the same thing an
actionscript script is doing in perl. It was not me who has written the
actionscript script, but I have seen this format many times. Pls see
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm I just want
%20's and not + in my post request.

This is what the flash script is sending (captured in Ethereal).

nc=Thu%20May%205%2002%3A51%3A24%20GMT%2B0200%202005&IdChannel=129&Insert%5Fdate=5%2F5%2F2005&key=1HTTP/1.1
100 Continue

Till now I have arrived till here. The only problem remaining is that the
LWP::UserAgent is encoding my % where I want them untouched.

nc=Thu%2520May%25205%252002%252051%252024%2520GMT%252B0200%25202005&IdChannel=127&Insert%2520date=5%252F5%252F2005&key=1HTTP/1.1
100 Continue

I think, that the problem that I have with LWP::UserAgent is that I do not
know how to define the charset to use and/or the encoding to use.

Any help is appreciated.

David

P.S. References (see encoding sections):


Alan J. Flavell said:
Hi I was experimenting with perl, on the POST method. I am using
LWP::UserAgent

$response = $browser->post( $url,
[ 'first name' => 'John',
'last name' => 'Doe',
'lastandfirst' => 'John Doe',
] );

If I post, the data is sent something like this
"&first+name=John&last+name=Doe&lastandfirst=John+Doe"

Check the definition of the form url encoding format. This is the
correct submission.
I would like the post to be something enocoded like so (dont ask me why!)
&first%20name=John&last%20name=Doe&lastandfirst=John&20Doe

Stop wanting that. It's not a defined form submission format.
You'd be creating a completely pointless incompatibility with web
interworking specifications.
This is sending me crazy.

Often happens when one wants the wrong thing. This has nothing to do
with Perl, by the way.
 
A

Alan J. Flavell

Sorry Alan, you are wrong is saying so.

See the authoritative specification,
http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
I want to do the same thing an actionscript script is doing in perl.
It was not me who has written the actionscript script, but I have
seen this format many times.

Nevertheless, it deviates from any forms submission format which is
defined in authoritative specifications, and I stand by the priniciple
that it's a bad idea to propagate such poor engineering.

But this has nothing to do with Perl, so I'm not going to discuss this
in great detail here.

That's urlencoding, yes, not application/x-www-form-urlencoded
format.

If you were to apply a urlencoding layer to your data first, then your
spaces would turn into %20. Then, application/x-www-form-urlencoded
would have to turn that into %2520 (%25 being the encoded percent
character).
I just want %20's and not + in my post request.

My advice continues to be that you should stop wanting that.
This is what the flash script is sending (captured in Ethereal).

nc=Thu%20May%205%2002%3A51%3A24%20GMT%2B0200%202005&IdChannel=129&Insert%5Fdate=5%2F5%2F2005&key=1HTTP/1.1

But this conforms to no published interworking specification; I don't
see any advantage in deviating from known specifications.
Till now I have arrived till here. The only problem remaining is that the
LWP::UserAgent is encoding my % where I want them untouched.

Of course, it's designed to do its proper job, not the piece of
misconceived "design" which you're trying to emulate.
I think, that the problem that I have with LWP::UserAgent is that I do not
know how to define the charset to use and/or the encoding to use.

That's got nothing to do with your stated problem, though.

good luck
 
D

David Joseph Bonnici

.....
use HTTP::Request::Common qw(POST);
use URI::Escape;
.....

and then do the request as follows. (It was quite painfull to find the right
manpage)

$response = $browser->request(POST $url,
Content => 'nc='.uri_escape('Fri May 6
03:09:09').'&Id='.'01'.'&'.'Insert%5Fdate'.'='.uri_escape('8/5/2005').'&key=1');

Like so, you have total control of what is sent in the post request.

I have a new problem now, being that: to have some sort of control of the
packet size of the request. Some post requests are splitted into several
small packets, and I think that this can be causing some problems, on the
server side (of which I have no control or debug information. I know that
the server should not bother about the transport layer, but you never know
how things are implemented.)


David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

form post URL encoded 4
CSV to quasi-XML 6
Which data serialization format? 9
First post 1
files.py (weird encoding error) 0
Help with Github??? 2
lwp POST and proxies 4
Learning to programm 1

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,466
Latest member
DrusillaYa

Latest Threads

Top