验证API连接错误

时间:2013-09-23 12:54:57

标签: php api

我有一个连接到API的代码,如下所示:

$response = file_get_contents($url . $guid . $api_key);
$response = json_decode($api_user);

但有时API不可用,并且脚本会抛出错误。如何验证以确认请求是否成功?

我试过了:

if($response = json_decode(file_get_contents($url . $guid . $api_key))) {
  // success
}

但我仍然得到“警告:file_get_contents ...无法打开流:HTTP请求失败”错误。

URL,GUID和APIKEY是正确的,通常它可以正常工作。但是如果不是,我只会收到错误报告。

0 个答案:

没有答案