Issue
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
Solution
I have resolved this issue , Maybe it will help someone
$client = new Client();
$result = $client->request("POST", $this->url,
[
'headers' => [
'Authorization' => 'Bearer ' . $this->ApiToken,
'Accept-Encoding' => 'gzip, deflate', //new line added
],
]);
$content = $result->getBody()->getContents();
Answered By - Nasir Awan Answer Checked By - Cary Denson (WPSolving Admin)