I am integrating an API in which I have to send my request in encrypted mode and for that I am using httpClient but when I tried this I am getting:
GuzzleHttp\Exception\RequestException
An error was encountered while creating the response
at vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:173
Now I have done same process using Postman but in that I got desired response:
Now I am unable to catch what is the real issue behind it; is there any header related issue or is there anything else?
The process for this API calling is also described as below
$config = 'ALL_DATA_FOR_REQUEST';
$httpClient = Http::timeout($config->timeout);
$httpClient->withHeaders($config->headers);
try {
if ($config->method === 'GET') {
$gatewayResponse = $httpClient->get($config->url, $config->encryptedRequestData ?? $config->requestData);
} elseif ($config->method === 'POST') {
$encryptedRequestData = $config->encryptedRequestData;
if ($encryptedRequestData && is_string($encryptedRequestData)) {
$httpClient->withBody($encryptedRequestData, trim($config->headers['Content-Type']));
$encryptedRequestData = [];
}
$gatewayResponse = $httpClient->post(
$config->url,
$encryptedRequestData ?? $config->requestData
);
}
} catch (\Exception $e) {
$curlMessage = $e->getMessage();
preg_match('/^[^\d]*(\d+)/', $curlMessage, $curlCode);
return \Ipay::response([
'statusCode' => 'ISE',
'status' => $curlMessage,
'data' => [
'curlCode' => $curlCode[1] ?? '-',
],
]);
}
I have also set my header content-type as text/plain.
Through some debugging I have found something which I think is related to it:
This error is found in curlfactory.php file in guzzlehttp and I think this is somewhere pointing me some error; so is this some third party error which I am consuming.
Any ideas please.
After researching I finally found that actual headers are
more details on X-Frame-Options header
but the vendor was sending x-frame option header which was not correct and it was caught in HTTP client
after this i contacted to vendor and they corrected it.