我有2個文件client.php和server.php。我想用curl發送從客戶端到服務器的頭文件,然後在服務器中讀取這些頭文件,但不幸的是我無法在服務器文件中獲取頭文件。我試圖通過使用getallheaders()
來做到這一點,但沒有顯示任何內容。然後我試着get_headers()
這說空,當我用var_dump
就可以了。PHP獲取頭部捲曲發送
我的客戶代碼: ` $ result = sendRequest(); echo「res:」。$ result;
function sendRequest()
{
$method = 'test';
$params = array();
$params["method"] = $method;
$post = http_build_query($params, "", "&");
$headers = array(
"API-Key: test",
"API-Key2: test2",
"API-Key3: test3",
"API-Key4: test4",
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, "http://example.com/server.php");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($curl, CURLOPT_HEADER, 1);
$ret = curl_exec($curl);
return $ret;
}
和server.php:
get();
function get()
{
$head = get_headers();
var_dump($head);
}
您正在使用什麼版本的PHP? –
服務器:Apache/2 X-Powered-By:PHP/5.3.20 – Rocket
我建議您的服務器上的錯誤已禁用。您是否可以插入您的代碼以提供更多信息: error_reporting(E_ALL); ini_set('display_errors',1); –