guzzlehttp \客户端卷曲错误18:转移关闭
当我尝试从API中获取数据时,我会遇到
我正在使用guzzlehttp \ client
laravel 6 ,
try {
$client = new Client();
$result = $client->request("POST", $this->url,
[
'headers' => [
'Authorization' => 'Bearer ' . $this->ApiToken
],
]);
$content = $result->getBody()->getContents();
return [
'bool' => true,
'message' => 'Success',
'result' => $content,
];
} catch (\Exception $exception) {
return [
'bool' => false,
'message' => $exception->getMessage()
];
}
此错误
cURL error 18: transfer closed with outstanding read data remaining (see https://curl.haxx.se/libcurl/c/libcurl-errors.html
I am using GuzzleHttp\Client
Laravel 6 and I am getting this error when I am trying to get Data from API, it's working fine on postman
Here is My Code
try {
$client = new Client();
$result = $client->request("POST", $this->url,
[
'headers' => [
'Authorization' => 'Bearer ' . $this->ApiToken
],
]);
$content = $result->getBody()->getContents();
return [
'bool' => true,
'message' => 'Success',
'result' => $content,
];
} catch (\Exception $exception) {
return [
'bool' => false,
'message' => $exception->getMessage()
];
}
getting this error
cURL error 18: transfer closed with outstanding read data remaining (see https://curl.haxx.se/libcurl/c/libcurl-errors.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经解决了这个问题,也许会对某人有所帮助
I have resolved this issue , Maybe it will help someone
错误代码18
卷曲错误18:转移封闭,按照卷曲错误指定的
由于它正在收到一个块的编码流,因此知道何时在块中剩下数据。当连接关闭时,Curl告诉最后一个收到的块是不完整的。因此,您获得此错误代码。
为什么要添加使用GZIP压缩格式编码的Accept编码?
为了解决上述问题,我们需要一个编码数据来保留数据包以接收所有问题,HTTP标头提供了编码,并且客户端IE IE告诉您支持哪些编码的服务器,然后服务器会相应地响应并告知服务器的客户端并告知服务器的客户端并告知服务器它可以选择内容编码的响应标头。
The error code 18
as specified by curl errors,
since it is receiving a chunked encoding stream it knows when there is data left in a chunk to receive. When the connection is closed,curl tells that the last received chunk was incomplete. Thus you get this error code.
Why adding a Accept Encoding with gzip compression format works?
To solve the above problem we need a encode the data to preserve the packets to receive all of it, HTTP headers provides encoding and for the client i.e you to tell the server which encoding is supported, then the server responds accordingly and informs the client of its choice with the Content-Encoding response header.