1

我正在使用 guzzle php 服务器客户端来获取结果。在数组中,我收到了标头详细信息,但没有返回预期结果。它与p3p有关吗?我在哪里做错了?guzzle php 客户端将如何导致正文?

        $url='xyz.com';
       $client = new \GuzzleHttp\Client();
       $options = array(
        'headers' => array(
            'host' => 'xyz.com',
            'Connection' => 'keep-alive',
            'User-Agent' => 'device name is mentioned here',
            'Accept-Encoding' => 'gzip, deflate',
            'Accept-Language' => 'en-US',
        ),
        'verify' => false,
        'debug' => false,
        'allow_redirects' => array(
            'max' => 5,
            'strict' => true,
            'referer' => false,
            'protocols' => array(
                'http',
                'https'
            ),
        ),
      );

    $response = $client->request('GET', $url, $options);
    print_r($response);

   Following is the result I have received
    GuzzleHttp\Psr7\Response Object
    (
    [reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
    [statusCode:GuzzleHttp\Psr7\Response:private] => 200
    [headers:GuzzleHttp\Psr7\Response:private] => Array
    (
        [Cache-Control] => Array
            (
                [0] => no-cache
            )

        [X-XSS-Protection] => Array
            (
                [0] => 1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube
            )

        [X-Content-Type-Options] => Array
            (
                [0] => nosniff
            )

        [Expires] => Array
            (
                [0] => Tue, 27 Apr 1971 19:44:06 EST
            )

        [P3P] => Array
            (
                [0] => CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en for more info."
            )

当我打印 print_r($response->getBody()); 它返回空的 customMetadata

GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #82
[size:GuzzleHttp\Psr7\Stream:private] => 
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
    (
    )
)
4

1 回答 1

1

$response->getBody()->getContents()

请参阅Guzzlehttp - 如何从 Guzzle 6 获取响应的正文?更多细节。

于 2018-03-20T16:56:30.540 回答