how to add parameter to HTTP header in Perl?(not fowwlow the ? in url)

A

Alont

this is the header IE send to server:
POST /services/test.asp HTTP/1.1
Cache-Control: no-cache
Cookie: ASPSESSIONIDCQTDRQQR=IEDGMDLBFKGNEBGBIKNOEDLN

paramater1=baozhuangxiang&ext=txt

I want Perl can send this header too, but I don't know how to add
"paramater1=baozhuangxiang&ext=txt " to the header?

$url='http://localhost/services/test.asp'
$request = HTTP::Request->new(POST => $url);

#before send the request, how I can add
"paramater1=baozhuangxiang&ext=txt" to the header?

$response = $lwp->request($request); #send request
if ($response->is_success) {
$data = $response->content;
 
J

John Bokma

Alont said:
this is the header IE send to server:
POST /services/test.asp HTTP/1.1
Cache-Control: no-cache
Cookie: ASPSESSIONIDCQTDRQQR=IEDGMDLBFKGNEBGBIKNOEDLN

paramater1=baozhuangxiang&ext=txt

I want Perl can send this header too, but I don't know how to add
"paramater1=baozhuangxiang&ext=txt " to the header?

$url='http://localhost/services/test.asp'
$request = HTTP::Request->new(POST => $url);

#before send the request, how I can add
"paramater1=baozhuangxiang&ext=txt" to the header?

http://johnbokma.com/perl/currencyconverter.html has an example of this.

So:

my $action = POST

'http://localhost/services/test.asp', [

parameter1 => 'baozhuangxiang',
ex => 'txt',
];

my $ua = LWP::UserAgent->new;
my $request = $ua->request( $action );

could do the trick in your case.
 
G

Gisle Aas

John Bokma said:
So:

my $action = POST

'http://localhost/services/test.asp', [

parameter1 => 'baozhuangxiang',
ex => 'txt',
];

my $ua = LWP::UserAgent->new;
my $request = $ua->request( $action );

This variable is misnamed as what's returned by $ua->request() is a
'response'.

BTW, you can shorten this to:

my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://localhost/services/test.asp', [
parameter1 => 'baozhuangxiang',
ex => 'txt',
]);
 
A

Alont

ʱ¼ä:19 Nov 2004 13:21:58 +0100
Gisle Aas said:
my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://localhost/services/test.asp', [
parameter1 => 'baozhuangxiang',
ex => 'txt',
]);

I think My Perl system is not same as yours, the module LWP::UserAgent
haven't the method"post" as you said, error info:

Can't locate object method "post" via package "LWP::UserAgent" at
 
G

Gisle Aas

Alont said:
ʱ¼ä:19 Nov 2004 13:21:58 +0100
Gisle Aas said:
my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://localhost/services/test.asp', [
parameter1 => 'baozhuangxiang',
ex => 'txt',
]);

I think My Perl system is not same as yours, the module LWP::UserAgent
haven't the method"post" as you said, error info:

Can't locate object method "post" via package "LWP::UserAgent" at

Your version of LWP is very old then. This method was introduced in
libwww-perl-5.60 more than 3 years ago.
 
J

John Bokma

Gisle said:
John Bokma said:
So:

my $action = POST

'http://localhost/services/test.asp', [

parameter1 => 'baozhuangxiang',
ex => 'txt',
];

my $ua = LWP::UserAgent->new;
my $request = $ua->request( $action );

This variable is misnamed as what's returned by $ua->request() is a
'response'.

Thanks, will update my examples.
BTW, you can shorten this to:

my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://localhost/services/test.asp', [
parameter1 => 'baozhuangxiang',
ex => 'txt',
]);

I try to write the examples on my pages a bit out, with a lot of
whitespace :)
 

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

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top