Chinaunix

标题: 411 Length Required -- lwp error,怎么回事? [打印本页]

作者: actan    时间: 2009-11-27 17:20
标题: 411 Length Required -- lwp error,怎么回事?
在用lwp请求一个网页

my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0. Gecko/2009032711 Ubuntu/8.04 (hardy) Firefox/3.0.8");

print "requesting ..... $url\n";
my $req = HTTP::Request->new(GET => $url);
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');



请求的后提示错误:  
411 Length Required

我加了这一句, 随便设置了下length:
$req->content_length('2387');


报错多了一句:
Content-Length header value was wrong, fixed at /usr/share/perl5/LWP/Protocol/http.pm line 186.

我只是客户端请求一个url,又不是应答
怎么还要浏览器的content-length呢?
作者: 兰花仙子    时间: 2009-11-27 17:30
请求长度是HTTP头部必须的。
一般LWP会自动加上。
perldoc lwpcook

有很多示例,照着copy一个就行。
作者: 撒哈拉里的鱼    时间: 2009-11-27 17:30
有了LWP::UserAgent对象后没必要自己创建request,直接get就可以了。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2