如何使用file_get_contents在代理后面发送标头

时间:2018-06-27 18:38:31

标签: php file-get-contents custom-headers

我知道这确实是一个愚蠢的问题,但是当我尝试在代理后面发送标头时,我没有做错什么,但是我的标头似乎没有用。贝娄是我的代码

<?php

$url = "http://example.com";

$PROXY_HOST = "139.59.2.*** ";
$PROXY_PORT = "    ****";





 $options =    array(
        'http' => array(
            'method' => "GET",
            'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT",
            'request_fulluri' => true,
            'header' =>
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36 \r\n" .
                "Accept: */*\r\n" .
                "Accept-Language: en-US,en;q=0.5\r\n" .
                "Accept-Encoding: gzip, deflate\r\n" .
                "Connection: keep-alive"

        )
    )
;

$contexts = stream_context_create($options);

print_r( get_headers($url) );

echo file_get_contents($url,false,$contexts);

?> 

但是我想在请求“ http://example.com”时设置标头,但是似乎在请求代理站点和代理站点的过程中使用标头的file_get_contents正在使用没有/ preconfigured用户代理的请求。从后端代理请求并到达目标站点时,如何设置自定义标头?还是真的不可能?

0 个答案:

没有答案
相关问题