문제

I have to make POST request to a URL which also contains GET variables (query string).

I tried the following (which looks like a most simepl/logical way) but it does not work:

my $ua = LWP::UserAgent->new;
my $res = $ua->post('http://my.domain/index.pl?login=yes', {
    username => $username, 
    password => $password
});

my.domain/index.pl does receive any requests but as soon as I remove query string "?login=yes" request is working correctly.

도움이 되었습니까?

해결책

my $res = $ua->post('http://my.domain/index.pl?login=yes', {
    username => $username, 
    password => $password
});

boils down to

use HTTP::Request::Common qw( POST );

my $req = POST('http://my.domain/index.pl?login=yes', {
    username => $username, 
    password => $password,
});

my $res = $ua->request($req);

By using print $req->as_string();, you can see that does exactly what you said it should do.

POST http://my.domain/index.pl?login=yes
Content-Length: 35
Content-Type: application/x-www-form-urlencoded

password=PASSWORD&username=USERNAME

The problem is elsewhere.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top