pcd*_*cdl 1 php https proxy curl stream
我试图通过HTTPS获取流的内容,但我必须通过HTTP代理.我不想使用cURL,而是使用fopen和context参数.
问题是,我无法通过HTTPS工作(HTTP工作正常).
这DOES NOT工作:
$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);
Run Code Online (Sandbox Code Playgroud)
这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;
Run Code Online (Sandbox Code Playgroud)
有人知道第一段代码有什么问题吗?如果它与cURL一起使用,必须有一种方法使它适用于上下文.我试图将上下文选项更改为一堆不同的值,但没有运气.
任何帮助将不胜感激 !
谢谢.
您没有指定确切的错误消息,请尝试添加ignore_errors => true.但是如果你400 Bad Request从Apache 那里得到一个,你可能遇到的问题是服务器名称指示和主机头不匹配.还有一个与此相关的PHP错误:https://bugs.php.net/bug.php?id = 63519
尝试以下修复,直到此错误得到解决:
$stream = stream_context_create(array(
'http' => array(
'timeout' => 20,
'proxy' => 'tcp://my-proxy:3128',
'request_fulluri' => true
),
'ssl' => array(
'SNI_enabled' => false // Disable SNI for https over http proxies
)
));
echo file_get_contents('https://my-stream', false, $context);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7649 次 |
| 最近记录: |