簡體   English   中英

使用URL中的GET變量發送POST請求(使用LWP :: UserAgent)

[英]Sending POST request with GET variables in URL (with LWP::UserAgent)

我必須向一個包含GET變量(查詢字符串)的URL發出POST請求。

我嘗試了以下(看起來像一個最simepl /邏輯方式)但它不起作用:

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

my.domain / index.pl確實接收到任何請求但是一旦我刪除查詢字符串“?login = yes”請求正常工作。

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

歸結為

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);

通過使用print $req->as_string(); ,你可以看到,這正是你所說的應該做的。

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

password=PASSWORD&username=USERNAME

問題出在其他地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM