简体   繁体   English

LWP :: Simple get的结果被截断

[英]Result of LWP::Simple get is truncated

I'm using perl to perform a get request on a url, and the results appear to be truncated. 我正在使用perl在url上执行get请求,结果似乎被截断了。

If I run 如果我跑

curl myurl | wc -l

the result is 1823, and if I create the following file foo.pl: 结果是1823,如果我创建以下文件foo.pl:

#!/usr/bin/perl

my $url = 'myurl';

use LWP::Simple;
my $content = get $url;
die "Couldn't get $url" unless defined $content;
print $content;

and run 并运行

./foo.pl | wc -l

the result varies from around 1300 to occasionally 1823. Manually inspecting the output shows that the output is broken mid-line when using perl. 结果从1300左右到偶尔1823.手动检查输出显示使用perl时输出中断。

What can be causing this? 是什么导致这个?

What happens if you turn buffering off? 如果你关闭缓冲会怎么样? I also agree with Karsten S. in checking the http headers for erroneous codes. 我也同意Karsten S.检查http标头的错误代码。 Finally, I'd also try storing the contents into an array just to see what happens. 最后,我还尝试将内容存储到数组中,看看会发生什么。

To turn off buffering, you could simply place a $|++ at the top of your script after your use statements. 要关闭缓冲,您可以在use语句之后将$|++放在脚本的顶部。 Again, a shot in the dark. 再次,在黑暗中拍摄。

To examine the http headers, you can use CGI . 要检查http标头,可以使用CGI Here's a little site with a good example on how to get the headers from the request: 这是一个小网站,提供了一个很好的示例,说明如何从请求中获取标头:

http://www.velocityreviews.com/forums/t24118-re-lwp-simple-header-information-problems.html http://www.velocityreviews.com/forums/t24118-re-lwp-simple-header-information-problems.html

Finally, try using an array, @contents , to store the contents from the webserver instead of a scalar, $contents . 最后,尝试使用数组@contents来存储来自Web服务器而不是标量$contents I've had times in the past where something is passed from the remote server that Perl misinterprets as a list. 我曾经有过一段时间从Perl误解为列表的远程服务器传递的东西。 I'm not sure if LWP::Simple accounts for these times but it can't hurt to try. 我不确定LWP::Simple是否会LWP::Simple这些时间,但尝试不会有什么坏处。 You might only be getting one part of the data and the rest is either getting overwritten or ignored altogether. 您可能只获得一部分数据,其余部分要么被覆盖,要么被忽略。 Placing the data into an array could help determine if that is happening. 将数据放入数组可以帮助确定是否发生了这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM