如何使用LWP :: UserAgent测试HTTP标头值 [英] How to test an HTTP header value using LWP::UserAgent

查看:166
本文介绍了如何使用LWP :: UserAgent测试HTTP标头值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我得到答案时,我可能会发布更多问题,但是可以了!

I may be posting more questions as I get answers, but here goes!

我目前正在尝试对我的大学用来自动下载带有SAT分数数据的文件的Perl脚本进行故障排除.

I am currently trying to troubleshoot a Perl script that my university used to use to automatically download files with SAT score data.

这个想法是通读某个帐户中的电子邮件;拔出循环号(在URL中使用);拼凑多个网址;然后使用 LWP::UserAgent 从服务器上获取文件并在其上执行其他Perl magicks他们.

The idea is to read through emails in a certain account; pull out the cycle number (which is used in the URL); piece together multiple URLs; and then use LWP::UserAgent to grab the files from the server and do other Perl magicks on them.

在我的调查中,我确定手动输入URL(从而限制了由用户运行的脚本,并且每次都替换了循环号)确实有效.

In my investigation I have determined that manually entering the URL (and thus limiting the script to be run by the user, with the cycle number being replaced each time) actually works.

在检查发送回的响应对象时,我首先注意到,失败的请求缺少以下行:

In examining the response objects sent back I noticed (first of all) that the following line is missing from the request that fails:

'_uri_canonical' => $VAR1->{'_request'}{'_uri'}

但是,它存在于成功的请求中.

However it is present in the request that succeeds.

如果你们中的任何一个可以告诉我为什么未成功的请求中缺少此行,您将表示感谢,但这不是我要问的.

If any of you can tell me why this line is missing in the unsuccessful request you will have my thanks, but that's not what I'm asking about.

我的问题与进一步调查有关,以了解为什么被拒绝.

My question pertains to further investigation to see why it's being rejected.

LWP::UserAgent的文档中,我注意到了这一点:

In the documentation for LWP::UserAgent I noticed this:

LWP内部生成的错误响应会将"Client-Warning"标头设置为值内部响应".如果需要将这些内部响应与远程服务器实际生成的响应区分开,则需要测试此标头值.

Error responses that LWP generates internally will have the "Client-Warning" header set to the value "Internal response". If you need to differentiate these internal responses from responses that a remote server actually generates, you need to test this header value.

我的问题:您如何实际测试标头值? (原谅任何无知;我是大学IT部门的一名实习生)

My question: how do you actually test that header value? (Pardon any ignorance; I'm an intern in my college's IT department)

推荐答案

实际上,它在该标头中放置了各种消息,您可以按以下方式获取这些消息:

It actually places a variety of messages in that header, which you can obtain as follows:

if (my $cw = $response->header('Client-Warning')) {
   die("Internal error: $cw\n");
}

仅当状态已经指示错误时才使用Internal response消息.其他时间使用诸如Redirect loop detectedMissing Authenticate header之类的其他消息.上面的代码将获取在那里显示的任何消息,而不仅仅是检查Internal response.

The Internal response message is only used when the status already indicates an error. Other messages such as Redirect loop detected and Missing Authenticate header are used at other times. The above code will get whatever message is present there rather than just checking for Internal response.

这篇关于如何使用LWP :: UserAgent测试HTTP标头值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆