我需要将这些标头传递给$context
变量,我尝试使用将值放入数组然后将其传递给函数,但我从函数 stream_context_create()
中收到 http 警告file_getcontents
$prod_id = 4322;
$tnxRef = "RT45635276GHF76783AC";
$mackey = "ADECNH576748GH638NHJ7393MKDSFE73903673";
$agent = $_SERVER['HTTP_USER_AGENT'];
$hash = hash('SHA512', $prod_id.$txnRef.$mackey);
$headers = array(
'http'=>(
'method'=>'GET',
'header'=>'Content: type=application/json \r\n'.
'$agent \r\n'.
'$hash'
)
)
stream_context_create($headers)
$url_returns = file_get_contents("https://test_server.com/test_paydirect/api/v1/gettransaction.json?productid=$prod_id&transactionreference=$txnRef&amount=$amount", false, $context);
$json = json_decode($url_returns, true);
错误:
[function.file-get-contents]:打开流失败:HTTP 请求失败!HTTP/1.1 400 错误请求`
这就是我得到的错误,有人可以帮忙举一个明确的例子。