【问题标题】:HTTP Error 500 when using curl in PHP在 PHP 中使用 curl 时出现 HTTP 错误 500
【发布时间】:2015-03-28 20:58:40
【问题描述】:
<?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 变量的同义词。在 xampp 上执行时出现 http 错误 500,之前工作正常,但现在出现此错误

【问题讨论】:

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


    【解决方案1】:

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

    在请求之前或请求时针对此 API 使用适当的身份验证。

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

    【讨论】:

      猜你喜欢
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-25
      • 2020-10-02
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多