- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 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:
Entity body is the term used for the body of an HTTP message. The entity body of requests and responses is inherently a PHP stream in Guzzle.
这意味着 EntityBody 对象可以用于 HTTP 请求和响应。
Client::post()
的方法签名是 post($uri = null, $headers = null, $postBody = null, array $options = array())。
正如您的代码片段中所见,您没有设置发布请求的正文。事实上,您所做的只是设置一些 uri 查询参数。
根据引用 #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+,但我目前无法对此进行测试。
引用资料:
关于php - GuzzleHttp 使用 gzip 发送压缩请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32720414/
如何使用 GuzzleHttp(版本 6.0)发出 post 请求。我正在尝试执行以下操作并出现错误 我得到图像值 Illuminate\Http\UploadedFile Object (
我有 vagrant 设置。我有一个名为 test-api.local 的域,这是 homestead laravel。当我尝试访问 https://test-api.local/ 时,它运行良好。
这是一个简单的代码片段,但它只是挂起并且没有响应。 $httpClient = new GuzzleHttp\Client(); // version 6.x $headers = [
我应该在我的 Get 请求中发送一些 JSON,服务器在 application/json 中返回一些数据作为响应: $url='http://example.com/var1=123&var2={'
我想在 Laravel 5.8 中使用 Http facade,但我注意到这个版本的 Laravel 中不包含 Http facade,所以我安装了 GuzzleHttp。 但现在我不知道如何用这个包
当我尝试连接到离线或不存在的主机时,出现异常: cURL error 6: Could not resolve host: somedomain.com 那你怎么用这些东西呢? ( https://l
我无法理解如何修改此 cURL进入 Laravel 5.8,得到 {"code":"11", "message":"invalid Request found", "status":"DECLINED
我正在使用 guzzle 查询我的 API。 $client = new Client(); $response = $client->post('xxxxxx',
如何使用 Guzzle 6 创建具有以下条件的 5 个异步请求: 所有请求同时开始 我希望所有请求的超时值为 500 毫秒。如果请求超时,我不希望它中断其他请求 如果请求返回非 200,我不希望它中断
我正在尝试处理请求状态代码,主要是检查状态是否为 200,以防无法处理。我使用一个名为“GuzzleHttp\Client”的包,当出现 404 时,它会给我一个错误: Client error: `
我正在使用 guzzle 查询我的 API。 $client = new Client(); $response = $client->post('xxxxxx',
如何使用 Guzzle 6 创建具有以下条件的 5 个异步请求: 所有请求同时开始 我希望所有请求的超时值为 500 毫秒。如果请求超时,我不希望它中断其他请求 如果请求返回非 200,我不希望它中断
我正在尝试像这个例子一样发出一个帖子请求: $response = $guzzle->post('http://www.website.com/abc.asp?2014:62/9/931/99999'
我同时使用 Guzzle和 Codeigniter 3.0 首次亮相。我也承认我是第一次使用 php 命名空间。 我正在尝试根据文档中提供的示例使用 Guzzle 发出一个非常简单的获取请求。 (Gu
我正在尝试运行 LaunchDarkly,在代码中它说我需要像这样初始化我的类 $client = new LDClient("MY_CLIENT_KEY"); 现在我可以做到了,但是下面发生的错误是
我使用了 GuzzleHttp,我创建了以下命令的请求: use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; $url = 'http://loca
我正在创建多个以下 GuzzleHttp\Psr7\Requests: use GuzzleHttp\Psr7\Request; $myRequest = new Request( 'GET'
在 Laravel 中,我使用 Leaguewrap 在 handle() 中用这段代码创建了一个命令图书馆: $api = new Api($_ENV['RIOT_KEY']); $staticDa
所以我正在使用 guzzleHttp,我可以获得我想要的响应并捕获错误。 我遇到的唯一问题是,如果基本 URI 错误,整个脚本就会失败...我如何进行某种检查以确保端点确实已启动? $client =
我将 GuzzleHttp 与 API REST 结合使用。我的参数在 $url_complete = 'http://apirest.com/?'.$params; $request = $clie
我是一名优秀的程序员,十分优秀!