为什么PHP的cURL在HTTP标头前面加上“ HTTP_”?

时间:2019-01-20 08:46:46

标签: php http curl header

我正在发送http标头X-SSID,但服务器将其作为HTTP_X_SSID接收。 我正在使用cURL,但这不是必需的;我只需要通过post方法发送此标头并获取内容。

这里是the code,我正在用来发出请求:

$ch = curl_init();

// ... other setup code; see link above for full context)

curl_setopt($ch, CURLOPT_HTTPHEADER, arrat(
  "X-SSID: {$ssid}",
  "X-API_VERSION: 2"
});

$server_output = curl_exec($ch);
var_dump($ssid, $server_output);
curl_close($ch);

Here's服务器如何看待请求:

["HTTP_X_SSID"]=>
string(32) "[truncated]"
["HTTP_X_API_VERSION"]=>
string(1) "2"

1 个答案:

答案 0 :(得分:2)

如果您正在检查php中的标头,请注意,标头是这样暴露的。

即发送X-test将产生一个全局变量$ HTTP_X_TEST