为什么Mojo :: Message :: Response返回一个空体?

时间:2017-07-13 06:02:18

标签: perl http mojolicious

我正在尝试使用Mojo::Message::Response访问$res->body对象的正文,但我得到一个空字符串。

如果我$res->to_string我得到以下

HTTP/1.1 200 OK
Client-SSL-Cert-Subject: /C=DE/ST=Bayern/L=xxxxx/O=xxxx/CN=oa.xxxxx.com
X-BEServer: DEHEREMEX52
Client-SSL-Cipher: ECDHE-RSA-AES256-SHA
Client-SSL-Cert-Issuer: /C=US/O=Blah, Inc./OU=See www.blah.net/legal-terms/OU=(c) 2012 Blah, Inc. - for authorized use only/CN=Blah Certification Authority - L1K
Persistent-Auth: true
X-CalculatedBETarget: blah.blah.blah.biz
Client-Date: Thu, 13 Jul 2017 05:50:47 GMT
Client-Response-Num: 3
Date: Thu, 13 Jul 2017 05:50:47 GMT
Server: Microsoft-IIS/8.5
Client-SSL-Warning: Peer certificate not verified
X-DiagInfo: DEHEREMEX52
Set-Cookie: ClientId=PZCOBXREXHBNPYAIEA; expires=Fri, 13-Jul-2018 05:50:48 GMT; path=/; HttpOnly
Set-Cookie: exchangecookie=565bea08845b4a9fb053ac5e7e60e16e; expires=Fri, 13-Jul-2018 05:50:47 GMT; path=/; HttpOnly
Set-Cookie: X-BackEndCookie=S-1-5-21-1409082233-362288127-725345543-9215=u56Lnp2ejJqByp3MyMvMmsbSmc3Jx9LLnsid0sfImZvSx8qZns/Omp7Nyc3PgYHNz87I0s/H0s7Nq8/KxcrPxcvH; expires=Sat, 12-Aug-2017 05:50:48 GMT; path=/ews; secure; HttpOnly
X-FEServer: BLAHBLAX
Content-Length: 0
Client-Transfer-Encoding: chunked
X-AspNet-Version: 4.0.30319
Request-Id: ea3453f9-83b0-42fa-88a0-3d16ac35a6a6
Client-Peer: 87.237.216.20:443
Cache-Control: private
Connection: Keep-Alive
X-Powered-By: ASP.NET
Content-Type: text/xml; charset=utf-8
Client-SSL-Socket-Class: IO::Socket::SSL

如果我print dump $res->content我得到以下内容(为清晰起见省略了部分),我想要的内容明确地在buffer中:

do {
  my $a = bless({
    asset           => bless({ auto_upgrade => 1, start_range => 0 }, "Mojo::Asset::Memory"),
    auto_decompress => 1,
    auto_relax      => 1,
    auto_upgrade    => 1,
    body            => 2,
    buffer          => "the content I want is here and there is a lot of it",
    events          => { read => [sub { ... }] },
    ...
    header_size     => 1363,
    headers         => bless({
    ...
    }, "Mojo::Headers"),
    pre_buffer      => "",
    raw_size        => 3973,
    read            => 'fix',
    real_size       => 2610,
    size            => 0,
    state           => "finished",
  }, "Mojo::Content::Single");
  $a->{read} = $a->{events}{read}[0];
  $a;
}

但是$res->body返回一个空字符串。我怀疑它与sizereal_size和内容被分块有关,但它是什么?

curl -v执行相同操作会返回以下标题:

HTTP/1.1 200 OK
Connection: Keep-Alive
Transfer-Encoding: chunked
Date: Fri, 14 Jul 2017 06:04:11 GMT
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.5
Cache-Control: private
request-id: ac058f09-a121-4d27-bbdf-ea7505e1ff33
Set-Cookie: ClientId=FLKNCOOKUWTCVQKSQTZQ; expires=Sat, 14-Jul-2018 06:04:12 GMT; path=/; HttpOnly
X-CalculatedBETarget: cihiuz.blah.xxx.biz
X-DiagInfo: XXXXXXXXXXX
X-BEServer: XXXXXXXXXXX
X-AspNet-Version: 4.0.30319
Set-Cookie: exchangecookie=f5013e861b6949539169122ab1af6046; expires=Sat, 14-Jul-2018 06:04:12 GMT; path=/; HttpOnly
Set-Cookie: X-BackEndCookie=S-1-5-21-1409082233-362288127-725345543-9215=u56Lnp2ejJqByp3MyMvMmsbSmc3Jx9LLnsid0sfImZvSx8qZns/Omp7Nyc3PgYHNz87I0s/H0s7Mq8/Jxc/Lxc7N; expires=Sun, 13-Aug-2017 06:04:12 GMT; path=/ews; secure; HttpOnly
Persistent-Auth: true
X-Powered-By: ASP.NET
X-FEServer: XXXXXXXXXXX

ADDED

我发现我可以使用$res->content->leftovers获取内容 - 这是正确的方法吗?

0 个答案:

没有答案