将代理与file_get_contents一起使用 [英] Using proxy with file_get_contents

查看:46
本文介绍了将代理与file_get_contents一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一个网站(例如x.com)获取有关我的应用程序的数据. 我使用php函数file_get_contents()来获取数据. 可以肯定的是,我的服务器的IP地址将显示在x.com的日志中. 有没有不用代理就可以隐藏服务器IP的方法吗?

I am getting data for my application from a website, say x.com. I use the php function file_get_contents() to fetch the data. It is sure that , my server's ip address will be shown in x.com 's logs. Is there any way to hide my server's ip without using proxy?

如果我有代理,如何将其与file_get_contents()一起使用?

我需要同时以HTTP POST和HTTP GET方法发送请求

I need to send the request in both HTTP POST and HTTP GET methods

推荐答案

test.php使用 http://ifconfig.me/ip

test.php using http://ifconfig.me/ip

代码/manual/zh-CN/function.file-get-contents.php

code modified from http://www.php.net/manual/en/function.file-get-contents.php

<?php

// Create a stream
$opts = array(
        'http'=>array(
            'method'=>"GET",
            'header'=>"Accept-language: en\r\n" .
            "Cookie: foo=bar\r\n",
            'proxy' => 'tcp://221.176.14.72:80',
            )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://ifconfig.me/ip', false, $context);

var_dump($file);

这篇关于将代理与file_get_contents一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆