これらのヘッダーを$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 Bad Request`
それは私が得るエラーです、誰かが決定的な例を手伝ってくれませんか。