仅当getAnalysis()
在我的Ubuntu计算机上运行时,它仍可在Mac的多个版本(包括最新版本)上运行时,才会出现以下错误。我尝试通过使用该curl_error
功能对错误进行故障排除,但未打印任何内容。
失败的:Ubuntu的使用PHP 7.2.24-0ubuntu0.18.04.2
和卷曲 7.58.0
。
他的工作是:苹果与PHP 7.3.9
和卷曲 7.64.1
。
错误:
<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>
An error occurred while processing your request.<p>
Reference #179.96cadf17.1580524623.c5f345a
</BODY></HTML>
码:
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;
}
我终于找到了解决方案。我只需要改变
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
至
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Expect:'));
原因是我的要求过大,需要让curl知道会发生什么