【发布时间】:2012-11-23 16:46:38
【问题描述】:
我正在尝试通过 HTTPS 获取流的内容,但我必须通过 HTTP 代理。 我不想使用 cURL,而是使用带有 context 参数的 fopen。
问题是,我无法让它通过 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);
这确实工作(cURL):
$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。 -
谢谢,但我试过了,但没有成功。我读了一些代码 sn-ps,人们在不将密钥更改为“https”的情况下发出 https 请求。这里唯一的区别是我使用的是代理:/
-
把key改成
https不正确!https://调用将使用http上下文,然后是底层ssl传输上下文。
标签: php curl https proxy stream