I get the following error only when running getAnalysis()
on my Ubuntu machine while it still works on several versions of Mac (including the newest version).
I tried troubleshooting the error by using the curl_error
function however nothing was printed out.
Failed on: Ubuntu with PHP 7.2.24-0ubuntu0.18.04.2
and curl 7.58.0
.
Worked on: Mac with PHP 7.3.9
and curl 7.64.1
.
Error:
<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>
An error occurred while processing your request.<p>
Reference #179.96cadf17.1580524623.c5f345a
</BODY></HTML>
Code:
function getAnalysis($text)
{
$APIKey = "APIKey";
$URL="https://www.APIURL.com/API/";
$data = json_encode(array('text' => $text));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "apikey:$APIKey");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
print("======================================\n");
print($result);
print("======================================\n");
curl_close ($ch);
return $result;
}
I found the solution finally. I just need to change
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
to
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Expect:'));
The reason was my request was to large and needed to let curl know what to expect