我正在尝试向API发出GET请求,但这给了我500 Http错误。
我在https://reqbin.com/上尝试了同样的方法,并且没有任何错误
我的代码有什么问题?
我的代码:
$addr = $_GET['addr'];
$api_key = 'secure';
$url = 'https://www.blockonomics.co/api/merchant_order/'.$addr;
$options = array(
'http' => array(
'header' => "Authorization: Bearer $api_key",
)
);
$context = stream_context_create($options);
$contents = file_get_contents($url, false, $context);
$object = json_decode($contents);
答案 0 :(得分:1)
您可以使用以下代码捕获任何错误消息:
<?php
$addr = $_GET['addr'];;
$api_key = 'your_api_key';
$url = 'https://www.blockonomics.co/api/merchant_order/'.$addr;
$options = array (
'http' => array (
'header' => "Authorization: Bearer $api_key",
'ignore_errors' => true
)
);
$context = stream_context_create($options);
$contents = file_get_contents($url, false, $context);
$object = json_decode($contents);
if($object->status != 200) {
echo $http_response_header[0]."\n".$contents;
}
这样,您将看到错误消息,告诉您什么地方出了错:
HTTP / 1.1 500内部服务器错误
{“状态”:500,“消息”:“找不到订单。”}