【问题标题】:Strawberry Perl and lwp - download and save doesn't workStrawberry Perl 和 lwp - 下载和保存不起作用
【发布时间】:2013-12-20 02:27:26
【问题描述】:

此代码在 ActiveState Perl 5.10 中有效,但在 Strawberry Perl 5.14 中失败。 它下载并部分保存 jpeg,从一开始只有 4Kb 左右。并且每次下载文件的大小都不同。 响应总是“200 OK”。 LWP 版本为 6.04

use 5.14.0;
use LWP::UserAgent;
use HTTP::Headers;

my $img = 'https://avoncontent6.com/assets/ru-ru/images/product/prod_5045704_1_613x613.jpg';

my $ua = new LWP::UserAgent;
my $hh = HTTP::Headers->new(
  'User-Agent' => 'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0',
  'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'Accept-Language' => 'en-us,en;q=0.7,ru;q=0.3',
  'Accept-Encoding' => 'gzip, deflate',
  'Connection' => 'keep-alive',
);
$ua->default_headers( $hh );
$ua->cookie_jar({});
$ua->timeout(20);

$ua->get($img, ':content_file' => "jpg/1.jpg");

标题是:

HTTP/1.1 200 OK
Date: Tue, 03 Dec 2013 20:32:14 GMT
Accept-Ranges: bytes
ETag: "031dd727cfce1:0"
Server: Microsoft-IIS/8.0
Content-Length: 149607
Content-Type: image/jpeg
Last-Modified: Tue, 22 Oct 2013 13:08:46 GMT
Client-Aborted: die
Client-Date: Tue, 03 Dec 2013 20:32:15 GMT
Client-Peer: 162.13.51.77:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=EssentialSSL CA
Client-SSL-Cert-Subject: /OU=Domain Control Validated/OU=Free SSL/CN=avoncontent6.com
Client-SSL-Cipher: RC4-SHA
Client-SSL-Socket-Class: IO::Socket::SSL
X-Died: read failed: Inappropriate I/O control operation at D:/perl/perl/vendor/lib/LWP/Protocol/http.pm line 414.
X-Powered-By: ASP.NET

【问题讨论】:

  • $response->status_line 是什么?如果取消超时会怎样?
  • status is "200 OK" 删除超时没有帮助,一切都一样:(
  • 我以为它遇到错误时改变了状态码,所以我之前没有注意到这个:X-Died: read failed: Inappropriate I/O control operation。不知道这意味着什么,但从套接字读取时出错。
  • 删除Accept-Encoding请求头有用吗?
  • 删除了接受编码标头 - 仍然相同。我也对答案中的 X-Died 标头一无所知。但是在 freebsd perl 5.14 下使用相同的脚本,这一切都像一个魅力。所以它要么在草莓中,要么在草莓的 libwww 中:(

标签: perl download lwp


【解决方案1】:

安装了旧版本的 libwww-perl-5.837

【讨论】:

  • 你能试试最新的 libwww-perl吗?您之前拥有的 6.04 不是最新的,Changes 列出了一些有趣的修复。
  • 不,cpan 说 6.04 是可用于我的设置的最新版本 :(
  • 那么你还应该修复其他问题。 CPAN shell 中的reload index 有帮助吗?还可以考虑升级Net::HTTP 模块。
猜你喜欢
  • 2012-11-24
  • 1970-01-01
  • 2020-03-18
  • 2012-01-25
  • 1970-01-01
  • 1970-01-01
  • 2011-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多