我正在使用LWP::UserAgent
向网址发送请求。但是在回复的某个时候,我得到了不完整的XML
回复。
代码
$args->{pua} = LWP::UserAgent->new();
$args->{header} = HTTP::Headers->new;
$args->{header}->header("Content-Type" => "text/xml", "SOAPAction" => $args->{soapaction});
$request = HTTP::Request->new( "POST", $args->{endpoint}, $args->{header}, $args->{xml});
$response = $args->{pua}->simple_request($request);
my $xmlResponse = $response->content;
在$xmlResponse
的某个时候,我得到了不完整的回复。为什么会这样?
ResponseHeader
Connection: close
Date: Tue, 19 May 2015 11:07:37 GMT
Server: nginx/1.6.2
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: text/xml;charset=ISO-8859-1
Client-Date: Tue, 19 May 2015 11:07:40 GMT
Client-Peer: 202.77.98.11:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN
答案 0 :(得分:1)
当LWP由于超时或其他读取错误而无法读取全身时,可能会返回不完整的响应。在这种情况下,$response->is_success
将true
而$response->code
将为200
,但响应标头将包含名为X-Died
的特殊标头。
所以你可以查看这个标题:
unless ($response->is_success) {
die "Response failed: ", $response->status_line;
}
if ($response->header('X-Died')) {
die "Response failed (internal): ", $response->header('X-Died');
}