Perl:HTTP::Request 中响应代码的值

发布于 2024-09-05 07:55:19 字数 578 浏览 2 评论 0原文

因此,我正在编写代码以从互联网获取文档。文档大小约为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

混浊又暗下来 2024-09-12 07:55:19

确保 Web 服务器未配置为删除来自脚本的请求(在本例中为 perl)。

Make sure webserver is not configured to drop requests from scripts in this case perl.

窝囊感情。 2024-09-12 07:55:19

当网络应用程序给您带来麻烦时,使用 Wireshark 进行调试

When network applications give you trouble, debug using Wireshark.

如果没结果 2024-09-12 07:55:19

Web 服务器(Apache/nginx)可能有一个用 PHP/Python/其他语言编写的后端应用程序。可能后端没有回答任何问题,因此 Web 服务器停止等待(达到超时)并在 http 请求上回答您 5xx(内部服务器)错误

一个很棒的测试工具是 curl-v:

curl --verbose --head "SOME URL"
  • --head 来仅获取 http 响应标头。
  • 如果来自浏览器上的同一主机一切正常,则您的 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:

curl --verbose --head "SOME URL"
  • --head to fetch only http response header.
  • If from same host on a browser everything is OK there is something in your http request header that make the difference. You can see con browser dev tool what you are sending and add them to curl with -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!).
  • Use -s (silent) and 2>&1 to send curl output through pipe to less/head/tail.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文