如何通过代理服务器执行HTTPS请求
代理服务器在debian上为tinyproxy
码
$context = stream_context_create([
'http' => [
'proxy' => 'tcp://xx.xx.xx.xx:8888',
'request_fulluri' => true
]
]);
echo file_get_contents('https://www.google.com', false, $context);
错误
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in C:\wamp\www\google\test.php on line 10
Warning: file_get_contents(https://www.google.com): failed to open stream: Cannot connect to HTTPS server through proxy in C:\wamp\www\google\test.php on line 10
参考方案
我建议使用cURL来做到这一点。用户在stackoverflow上的某个地方说了这一点,我完全同意。
file_get_contents()是一个简单的螺丝刀。非常适合简单的GET
请求,其中标头,HTTP请求方法,超时,cookiejar,
重定向,其他重要的事情都没有关系。使用setopt的cURL
是几乎可以想到的所有选项的动力钻。
<?php
$url = 'https://www.google.com';
// to check your proxy
// $url = 'http://whatismyipaddress.com/';
$proxy = '50.115.194.97:8080';
// create curl resource
$ch = curl_init();
// set options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // read more about HTTPS http://stackoverflow.com/questions/31162706/how-to-scrape-a-ssl-or-https-url/31164409#31164409
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
echo $output;
?>
AJAX和file_get_contents - php我有一个使用file_get_contents的脚本,然后解码返回的JSON ...$urlone = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=f…
PHP:file_get_contents($ loc)失败 - php我只是将一个项目从localhost移到了我的远程服务器上,并且注意到我的某些脚本停止工作了。最重要的是依赖file_get_contents()从另一个脚本中获取JSON值的脚本。PHP版本是5.2.4allow_url_fopen开启 警告:file_get_contents() [function.file-get-contents]:php_netw…
vfsstream:file_get_contents()无法打开流:stream_open调用失败 - php我已经设置了vfsstream块设备,并且尝试在其上调用file_get_contents()。但是,对vfsStreamWrapper::stream_open的调用失败,因此无法打开流。这是我的代码:$this->root = vfsStream::setup('root'); $this->root->addChi…
如何通过php标头重定向传递在GET字符串中接收的变量? - php用户提交表单后,我正在从Aweber接收GET字符串中的值。我将变量发送给我,然后将其提交到SMS网关,以通过短信通知第三方提交。这是我的问题。我需要将在php标头中执行传出SMS命令的页面重定向到另一个页面,该页面最终显示从Aweber发送的GET变量。我可以在第一页中检索变量及其值。如何将它们传递到第二页?这是我在第一页(sms.php)上用来收集Awe…
如何在另一个php页面上的字符串变量中获取一个php页面的输出 - php我正在染色,知道该怎么做。其实我有两个php页面。说出page1.php和page2.php。现在说在page1.php中,我们有类似<?php $id=$_GET['id']; // do some processing with mysql database // do some more processing $name=…