如何在guzzle 6中压缩(gzip)请求的主体

时间:2016-08-10 16:46:45

标签: php guzzle guzzle6

需要将压缩(gzip)主体发送到服务器

e.g。

    protected function postOrPutData($method, $data, $type, $uri = null, array $options = [])
    {
        $requestBody = $this->serializer->serialize($data, 'json');

        $request  = new Request($method, $uri, [], $requestBody);
        $response = $this->httpClient->send($request, $options);

        return $this->serializer->deserialize((string) $response->getBody(), $type, 'json');
    }

1 个答案:

答案 0 :(得分:-1)

我认为你也可以从similar question about pure cURL获得灵感。

尝试在Guzzle中使用此自定义设置(我假设您正在使用cURL处理程序):

$options['curl'] = [CURLOPT_ENCODING => 'gzip'];

$request  = new Request($method, $uri, [], $requestBody);
$response = $this->httpClient->send($request, $options);