vendredi 31 janvier 2020

Any suggestions on error from curl_exec in php?

I get the following error when running getAnalysis() on my Ubuntu machine but I do not get it when I run this error on any macs(Tried several different versions of Mac OS including the newest version). I think curl is not understanding the reply back from the server but not sure how to trouble shoot it. I tried the curl_error function to see what the last error was but nothing printed out. Any help would be appreciated

I am using PHP 7.2.24-0ubuntu0.18.04.2 with curl 7.58.0 on my ubuntu machine.

It worked on PHP 7.3.9 with curl 7.64.1 on my mac

Error:

======================================
<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>
An error occurred while processing your request.<p>
Reference&#32;&#35;179&#46;96cadf17&#46;1580524623&#46;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;
}



Aucun commentaire:

Enregistrer un commentaire