我试图通过HTTPS获取流的内容,但我必须通过HTTP代理。 我不想使用cURL,而是使用fopen与上下文参数。PHP - https流通过http代理
事情是,我不能让它通过HTTPS工作(虽然HTTP工作正常)。
这不工作:
$stream = stream_context_create(Array("http" => Array("method" => "GET",
"timeout" => 20,
"proxy" => "tcp://my-proxy:3128",
'request_fulluri' => True
)));
echo file_get_contents('https://my-stream', false, $context);
这DOES工作(卷曲):
$url = 'https://my-stream';
$proxy = 'my-proxy:3128';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
是否有人知道什么是错的第一段代码?如果它与cURL一起工作,就必须有一种方法来使其与上下文一起工作。 我试图将上下文选项更改为一堆不同的值,但没有运气。
任何帮助将不胜感激!
谢谢。
从我记得,传递给'stream_context_create'阵列中的关键是协议将会被使用。尝试将密钥从http切换到https。 – sberry
谢谢,但我试过了,没有运气。我阅读了一些代码片段,在这里人们发出https请求,而不必将密钥更改为“https”。唯一的区别是我使用的是代理服务器:/ – pcdl
将密钥更改为“https”不正确! 'https://'调用将使用'http'上下文,然后使用底层'ssl'传输上下文。 –