Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用带有文件\u获取\u内容的代理_Php_Proxy_File Get Contents - Fatal编程技术网

Php 使用带有文件\u获取\u内容的代理

Php 使用带有文件\u获取\u内容的代理,php,proxy,file-get-contents,Php,Proxy,File Get Contents,我正在从一个网站(比如x.com)获取应用程序的数据。 我使用php函数file_get_contents()获取数据。 可以肯定的是,我的服务器的ip地址将显示在x.com的日志中。 有没有办法在不使用代理的情况下隐藏服务器的ip 如果我有一个代理,如何将其与文件\u get\u contents()一起使用 我需要使用HTTP POST和HTTP GET方法发送请求 代码修改自 绝对同意farmer1992 对于通过SSL+代理的文件\u获取\u内容存在问题的任何人,PHP的stream\u

我正在从一个网站(比如x.com)获取应用程序的数据。 我使用php函数file_get_contents()获取数据。 可以肯定的是,我的服务器的ip地址将显示在x.com的日志中。 有没有办法在不使用代理的情况下隐藏服务器的ip

如果我有一个代理,如何将其与文件\u get\u contents()一起使用

我需要使用HTTP POST和HTTP GET方法发送请求

代码修改自


绝对同意farmer1992

对于通过SSL+代理的
文件\u获取\u内容
存在问题的任何人,PHP的stream\u context\u create存在一个已知错误:

幸运的是,解决方法很简单。基本上,当解析代理和SSL配置的“https”目标URL时,上下文创建者会感到困惑。您只需在SSL配置中设置SNI_服务器名称

$targetUrl = "https://something.com";
$sniServer = parse_url($targetUrl, PHP_URL_HOST);
$params = array('your'=>'post','params'=>'here');
$ctxConfig = array(
    'http' => array(
        'method' => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded'."\r\n",
        'content' => http_build_query($params),
        'proxy' => 'tcp://12.34.56.78:3128',
        'request_fulluri' => true
    ),
    'ssl' => array( 
        'SNI_enabled' => true,
        'SNI_server_name' => $sniServer
    )
);
$context = stream_context_create($ctxConfig);
file_get_contents($targetUrl,false,$context)

希望这能节省一些时间

文件\u获取\u内容获取参数流\u或\u上下文您可以将您的代理放入其中查看此我尝试了此操作,但我遇到以下错误,即未指定内容长度。因此我提供了参数content length和offset。但它仍然不起作用。服务器端始终知道您的ip,或者无法与您交换数据(我是指http). 在某些情况下,您可以放置一个像X-Forward-For:
fakeip
这样的头来告诉服务器您的fakeip,但是服务器端将决定要使用哪个ipuse@J你是什么样的代理人use@J尝试为yaThanks制作一个。它正在工作。对于帖子请求,我必须提供内容类型和长度,对吗?我使用post在我的服务器上进行了测试..并在同一台服务器上请求了一个文件并检查了日志..在日志中,我的服务器的ip是可见的:(代理服务器似乎已将您的ip添加到X-Forward-For,并且您的服务器根据您的服务器端读取ip的方式使用了iTing。如果您知道iThanks,您可以使用自定义方式。$params只是您打算发送到服务器的POST参数。我在上面添加了一个澄清声明。未定义变量$domainThanks。我已更正此abov。)e、 以前的
$domain
现在是
$sniServer
$targetUrl = "https://something.com";
$sniServer = parse_url($targetUrl, PHP_URL_HOST);
$params = array('your'=>'post','params'=>'here');
$ctxConfig = array(
    'http' => array(
        'method' => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded'."\r\n",
        'content' => http_build_query($params),
        'proxy' => 'tcp://12.34.56.78:3128',
        'request_fulluri' => true
    ),
    'ssl' => array( 
        'SNI_enabled' => true,
        'SNI_server_name' => $sniServer
    )
);
$context = stream_context_create($ctxConfig);
file_get_contents($targetUrl,false,$context)