在PHP中使用curl时出现HTTP错误500

时间:2015-03-28 20:58:40

标签: php http curl asp.net-web-api

<?php
ini_set('display_errors', 1);
set_time_limit(0);
$word = "product";
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://words.bighugelabs.com/api/2/ad63536b2f8108efe8c07295746c5a09/$word/json"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec($ch); 
$info = curl_getinfo($ch); 
curl_close($ch);

$bigarray = array();

if ($info['http_code'] == 200) { 
  $result = json_decode($data, true); 
  $final = json_encode($result,JSON_PRETTY_PRINT);
  file_put_contents("results.json", $final);
    $bigarray = $result["noun"]["syn"];

  }



 else echo "Http Error: ".$info['http_code'];

foreach ($bigarray as $value) {
echo $value."<br>";
}   
?>

此代码显示$ word variable的同义词。当在xampp上执行时,会给出http错误500,之前工作正常但现在出现此错误

1 个答案:

答案 0 :(得分:0)

在这种情况下,HTTP状态代码500表示API密钥不再有效或是非活动密钥。

在请求之前或之后对此API使用正确的身份验证。

此处描述了请求API密钥:https://words.bighugelabs.com/api.php