我使用GuzzleHttp与API REST。我的参数在
$url_complete = 'http://apirest.com/?'.$params;
$request = $client->post(
$url_complete,
);
当我搜索解决方案时,我只得到EntityBody对象的解决方案(http://guzzle3.readthedocs.org/http-client/entity-bodies.html)。但是EntityBody是API的响应。我不需要读压缩数据,我必须发送它。
你知道通过GuzzleHttp发送压缩(gzip)数据到API REST的方法吗?
引用Ref #1:
实体正文是用于HTTP消息正文的术语。请求和响应的实体体本质上是Guzzle中的PHP流。
这意味着EntityBody对象可以用于HTTP请求和响应。
Client::post()
的方法签名是post($uri = null, $headers = null, $postBody = null, array $options = array()).
在您的代码片段中可以看到,您没有设置post请求的主体。事实上,你所做的只是设置一些uri查询参数。
基于Ref #2, #3和#4:你可能会想要做这样的事情:
$body = EntityBody::factory(fopen($file_location));
$body->compress(); //compresses the body using the deflate php stream filter
$request = $client->post($uri, $headers, $body, $options);
$response = $client->send($request);
我应该声明我从来没有这样做过,我在过去1.5年的大部分时间里一直在使用v4+,目前我无法对此进行测试。
引用:
- 实体机构
- 实体体-压缩
- 使用请求对象- POST请求 Guzzle 3 - Client.php