我有下面的方法,即使用cURL从webserver获得响应。
function login (string $_login, string $_password) : string {
$url = "https://acweb.net.br/api/orcamentos/login";
$fields = [
"login" => $_login,
"password" => $_password
];
$headers = [
"Try" => "Trying"
];
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
return curl_exec( $ch );
}
它工作正常!
我可以使用以下命令获取**$_POST**的值
print_r ($_POST)
但我无法获得CURLOPT_HTTPHEADER的值。
编辑:
我试过了:
print_r ($_SERVER)
但它不在那里。
如何获得CURLOPT_HTTPHEADER的值?
- $_服务器中的所有HTTP标头*:
[HTTP_HOST] => ctemcasb.com.br
[HTTP_CONNECTION] => keep-alive
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
[HTTP_SEC_FETCH_USER] => ?1
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
[HTTP_SEC_FETCH_SITE] => none
[HTTP_SEC_FETCH_MODE] => navigate
[HTTP_ACCEPT_ENCODING] => gzip, deflate, br
[HTTP_ACCEPT_LANGUAGE] => pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
[HTTP_COOKIE] => PHPSESSID=j4cqqdc83fia68nk0gsglqk1bv
HTTP_TRY,不存在。
现在呢?
我在服务器中这样做:
print_r($_SERVER)
以及
print_r ($_SERVER["HTTP_TRY]);
1条答案
按热度按时间yxyvkwin1#
标头不应该是一个关联数组,它应该是一个字符串的索引数组。
然后您应该能够使用以下命令访问标头:
$_SERVER['HTTP_TRY']
,因为自定义标头以HTTP_
为前缀