[英]Perl: Using HTTP::Request::Common to post with authentication
[英]Perl HTTP Post Authentication
只是想知道是否有人可以看到這不是將用戶名和密碼傳遞給Web服務器?
my $ua = LWP::UserAgent->new();
$ua->credentials("10.64.1.1:80", "realm-name", 'alexis','alexispass');
my $resp = $ua->post("http://10.64.1.1:80/CGI/Execute",
{ "Key" => "XML" ,
"value" => "<setBackground><background><image>http://10.64.2.2/7945-65 NFullSize.png</image><icon>http://10.64.2.2/7945-65/NThumSize.png</icon></background></setBackground>"});
print $resp->content;
謝謝亞歷克西斯
可能這可以幫助您:
#!/usr/bin/perl -w
use strict;
use HTTP::Request::Common;
require LWP::UserAgent;
my $usr = 'alexis';
my $pass = 'alexispass';
my $URL = 'http://10.64.1.1:80/CGI/Execute';
my $ua = new LWP::UserAgent;
$ua->timeout(20);
my $request = POST $URL,
Content_Type => [ 'Content_Type here' ],
Content => [ 'Content here' ];
$request->authorization_basic($usr, $pass);
my $response = $ua->request($request);
print $response->content;
該腳本使用HTTP :: Request :: Common中的POST()函數。 如果我理解正確,那么您的POST請求部分應如下所示:
my $request = POST $URL,
[ XML => '<setBackground><background><image>http://10.64.2.2/7945-65 NFullSize.png</image><icon>http://10.64.2.2/7945-65/NThumSize.png</icon></background></setBackground>'
];
該請求創建對象,如下所示:
POST http://10.64.1.1:80/CGI/Execute
Content-Length: 66
Content-Type: application/x-www-form-urlencoded
XML=<setBackground><background><image>http://10.64.2.2/7945-65 NFullSize.png</image><icon>http://10.64.2.2/7945-65/NThumSize.png</icon></background></setBackground>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.