Perl LWP useragent->请求返回200而不是302

时间:2013-03-07 03:49:36

标签: perl http lwp

我是Perl的新手,但必须使用Perl脚本为第三方填写一些Web表单。 当我们在第一个环境中运行脚本时,它具有正确的输出:

HTTP/1.0 302 Moved Temporarily
Cache-Control: private, max-age=10800, pre-check=10800
Connection: close
Date: Thu, 07 Mar 2013 03:32:20 GMT
Via: 1.0 some.host (squid/3.1.10)
Location: http://l**************
Content-Length: 0
Content-Type: text/html
Last-Modified: Tue, 12 Feb 2013 18:12:56 GMT
Client-Date: Thu, 07 Mar 2013 03:26:23 GMT
Client-Peer: 10.****************
Client-Response-Num: 1
Client-Warning: Redirect loop detected (max_redirect = 0)
Set-Cookie: ************************
Set-Cookie: ***********************
X-Cache: MISS from rhe-proxy.prod.lan
X-Cache-Lookup: MISS from some.host

在不同的环境中,它有这样的响应:

HTTP/1.0 200 OK
Content-Type: text/html
Client-Date: Thu, 07 Mar 2013 03:25:21 GMT
Client-Peer: 10.**************
Client-Response-Num: 1
Client-Warning: Redirect loop detected (max_redirect = 0)
Refresh: 0; URL=https://some.url

<HTML></HTML>

脚本是这样的:

use strict;
use vars qw($opt_h $opt_v $opt_X);
use Getopt::Std;
use LWP;
use HTTP::Request::Common;
use HTTP::Cookies;
use HTML::Parser;
$opt_h ||= "exmaple.com";
my $username = "abc";            # replace with your login username
my $password = "edf1";           # replace with your login password

my $login_url = "someurl";
my $request;
my $response;

my $ua = new LWP::UserAgent(max_redirect => 0);
my $cjar = new HTTP::Cookies;

$request = new HTTP::Request(POST => $login_url);
$request->content_type("application/x-www-form-urlencoded");
$request->content("username=$username&password=$password");

print $request->as_string();
$response = $ua->request($request);
print $response->as_string();

谁能告诉我这种差异的可能原因是什么? 它们是防火墙和不同代理的后面,是代理导致问题还是脚本本身的一些问题?

顺便说一句,第一个有刷新:0头,我应该如何处理这个问题,这会对问题有任何暗示吗?

感谢。

0 个答案:

没有答案
相关问题