Perl:HTTP::Request 中响应代码的值
因此,我正在编写代码以从互联网获取文档。文档大小约为 200 KB。这是代码:
#!/usr/local/bin/perl -w
use strict;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $url = "SOME URL";
my $req = HTTP::Request->new(GET => $url);
my $res = $ua->request($req);
if($res->is_success){
print $res->content ."\n";
}
else{
print "Error: " . $res->status_line;
}
现在,唯一的问题是我无法提及 URL 是什么。
但是,输出是:“错误:500 读取超时”。当我检查外部链接时,数据下载时间不到 5 秒。
我什至把超时时间改成了1000s,还是不行。我应该如何找到与回复相关的更多信息?文件的大小(大约 200KB)也不足以保证读取超时。服务器也不繁忙,每当我检查浏览器上的链接时都没有出现问题。
谢谢。
So, I am writing a code to get a document from the internet. The document size is around 200 KB. This is the code:
#!/usr/local/bin/perl -w
use strict;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $url = "SOME URL";
my $req = HTTP::Request->new(GET => $url);
my $res = $ua->request($req);
if($res->is_success){
print $res->content ."\n";
}
else{
print "Error: " . $res->status_line;
}
Now, the only problem is I can't mention what the URL is.
However, the output is: "Error: 500 read timeout". When I checked the link externally, the data is being downloaded in under 5 seconds.
I even changed the timeout to 1000s, but it still didn't work. How should I go about finding more information related to the response? The size of the file (around 200KB) is also not big enough to warrant a read timeout. The server is also not a busy one, didn't give a problem whenever I checked the link on the browser.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保 Web 服务器未配置为删除来自脚本的请求(在本例中为 perl)。
Make sure webserver is not configured to drop requests from scripts in this case perl.
当网络应用程序给您带来麻烦时,使用 Wireshark 进行调试。
When network applications give you trouble, debug using Wireshark.
Web 服务器(Apache/nginx)可能有一个用 PHP/Python/其他语言编写的后端应用程序。可能后端没有回答任何问题,因此 Web 服务器停止等待(达到超时)并在 http 请求上回答您 5xx(内部服务器)错误。
一个很棒的测试工具是
curl
和-v
:--head
来仅获取 http 响应标头。-H, --header
中
。调整curl参数Web服务器无法判断收到的http请求是否来自Web浏览器、脚本或其他任何东西(协议魔法!)。-s
(静默)和2>&1
来发送curl输出通过管道到less/head/tail。The web server (Apache/nginx) may have a backend app written on PHP/Python/whatever. Probably that backend isn't answering anything, so the web server stop waiting (reach timeout) and answer to you on the http request a 5xx (internal server) error.
One great tool for testing is
curl
with-v
:--head
to fetch only http response header.-H, --header <header>
. Adjusting curl parameters web server can't tell if the received http req is from a web browser, a script, or anything else (protocols magic!).-s
(silent) and2>&1
to send curl output through pipe to less/head/tail.