从 cURL 获取 CURLOPT_HTTPHEADER 的值

Get the value of CURLOPT_HTTPHEADER from cURL

我有下面的方法是使用 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_headers $_SERVER:

[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]);

headers 不应该是关联数组,它应该是字符串的索引数组。

$headers = [
    'Try: Trying',
    'Content-Type: text/html',
    ...
]; 

那么您应该可以通过以下方式访问 header:$_SERVER['HTTP_TRY'] 因为自定义 header 的前缀是 HTTP_