Perl HTTP 后认证

标签 perl http authentication post

只是想知道是否有人能看出为什么这没有将用户名和密码传递给 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>

关于Perl HTTP 后认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19842400/

相关文章:

perl - 为多行引用的单词添加注释的最佳方法是什么?

perl - 使用 perl 替换单词时出现错误

perl - 为什么 perl qx 在 Mojolicious::Lite 中挂起,但在普通程序中却挂起?

ios - HTTPURLResponse allHeaderFields Swift 3 大写

c# - 如何使用 C# 远程对 Stack Overflow 帖子投反对票?

windows - 如何获得计算机的平均 CPU/处理器使用率?

http - http非长连接模式有什么用

ruby-on-rails - rails 和 node.js 之间的共享身份验证与 redis 存储

angularjs - 如何在 $http.get().then() AngularJS 中使用 Authentication 对象

authentication - SSL 的优势值得你费心费力吗?