繁体   English   中英

从枪口反应中截断身体内容

[英]Cutoff body content from Guzzle response

我正在使用Guzzle登录页面,然后解析DOM以获得下载链接。 但是,登录后我不会收到完整的DOM。 带有下载链接的HTML即将以DOM字符串开头,然后被截断。

有人知道这可能是什么原因吗?

该页面位于登录名后面,不能公开访问。

注意:我无法共享URL或登录数据,因此很可能无法复制该问题。

到此为止

</SCRIPT>
  <TABLE   ALIGN=LEFT CELLSPACING=0 CELLPADDING=1 style='WIDTH:99%;max-width:1000px;'>                              

(此后什么也没有,但是应该以某种方式不在响应中)

PHP:7.1.26

食味:6.3.3

一些代码,如果有帮助的话:

$response = self::$client->get(self::getConfig()['baseurl'] . '/' . parse_url($mainScreenUri)['path'], [
                'query'   => $query_params,
                'sink'    => date('Y.m.d_H-i-s') . '_sink_.txt',
                'debug'   => TRUE,
                'headers' => [
                    'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
                    'Accept'     => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                    'Host'       => 'snip',
                ]
            ]
        );

        $x = $response->getBody()->__toString();
        file_put_contents(date('Y.m.d_H-i-s') . '.txt', $x);

由此创建的两个文件都将被剪切,并且不会显示整个正文。

响应调试:

* Found bundle for host snip: 0x5625c0ab6100 [can pipeline]
* Re-using existing connection! (#0) with host snip
* Connected to snip port 443 (#0)
> GET snip HTTP/1.1
Host: snip
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Cookie: snip

< HTTP/1.1 200 OK
< Date: Tue, 25 Jun 2019 12:55:56 GMT
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.26
< X-Frame-Options: sameorigin
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html
< 
* Curl_http_done: called premature == 0
* Connection #0 to host snip left intact

编辑使用流只取一次我有同样的问题几个字节。

/** @var \GuzzleHttp\Promise\Promise $promise */
        $promise = self::$client->getAsync(self::getConfig()['baseurl'] . '/' . parse_url($mainScreenUri)['path'], [
                'query'           => $query_params,
                'sink'            => 'snip' . date('Y.m.d_H-i-s') . '_sink_.txt',
                'debug'           => $resource,
                'stream'          => TRUE,
                'headers'         => [
                    'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
                    'Accept'     => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                    'Host'       => 'snip',
                    //                    'Referer'    => 'snip/popup.php?user=' . self::getConfig()['username'] . '&pwi=' . $pwi . '&pwh=' . $hpw,
                ],
                'allow_redirects' => [
                    'max' => 50,
                ]
            ]
        );

        /** @var \GuzzleHttp\Psr7\Response $response */
        $response = $promise->wait();

        /** @var \GuzzleHttp\Psr7\Stream $body */
        $body = $response->getBody();

        $dataRead = "";
        while (!$body->eof()) {
            $data     = $body->read(1024);
            $dataRead .= $data;
        }

与其他所有内容一样, $dataRead被截断。

我发现了问题。 这是一个已损坏的参数,服务器决定返回损坏的HTML,而不是错误消息或什么也没有。

暂无
暂无

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

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