Perl HTTP Post身份验证

时间:2013-11-07 17:18:21

标签: perl http authentication post

只是想知道是否有人可以看到hwy这没有将用户名和密码传递给网络服务器?

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;

由于 亚历

1 个答案:

答案 0 :(得分:1)

可能这可以帮到你:

#!/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>