我需要這些頭通入$context
變量,我試圖使用把值到一個數組,然後將其通入stream_context_create()
功能,但我GET HTTP從file_getcontents
功能傳遞報頭插入file_get_contents()函數用於JSON請求
$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]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request`
那是錯誤我得到的,可以請人一個明確的例子幫助。
OPS,[主要來源](http://stackoverflow.com/questions/15497253/passing-headers-into-file-get-contents)不存在! – 2016-01-22 01:03:29
頁面找不到重複的鏈接... – urban 2016-05-03 19:57:37