[英]How to use file_get_contents with proxy?
当我将file_get_contents
与SSL和代理一起使用时,出现以下错误:
警告:file_get_contents():SSL操作失败,代码为1。OpenSSL错误消息:error:1408F10B:SSL例程:ssl3_get_record:D:\\ XAMPP \\ htdocs \\ instahu \\ app \\ vendor \\ classes \\ instagram.php中的版本号错误154
警告:file_get_contents( https://www.instagram.com/explore/tags/test/ ):无法打开流:无法通过D:\\ XAMPP \\ htdocs \\ instahu \\ app \\ vendor \\ classes \\中的代理连接到HTTPS服务器instagram.php在154行
protected function curl_send($url,$post = null,$headers = null) {
global $settings;
global $language;
global $lng;
global $currentUrl;
$file = file_get_contents("http://" . $_SERVER['HTTP_HOST'] . "/app/vendor/classes/proxy.txt");
$file = explode("", $file);
if (count($file) == 0) {
include_once __DIR__.'/../../templates/500.php';
exit();
}
$mysqli = new mysqli($settings['db']['host'],
$settings['db']['user'],
$settings['db']['pass'],
$settings['db']['name']);
$exe_proxies = $mysqli->query('SELECT * FROM `proxy_used`');
$proxies = [];
while ($row = $exe_proxies->fetch_assoc()) {
$proxies[] = $row['proxy'];
}
foreach ($file as $proxy) {
if (!in_array($proxy, $proxies)) {
$target_proxy = $proxy;
break;
}
}
if (!isset($target_proxy)) {
$mysqli->query('DELETE FROM `proxy_used`');
$target_proxy = $file[0];
}
$mysqli->query('INSERT INTO `proxy_used` SET `proxy` = "' . $target_proxy . '"');
$target_proxy = 'tcp://'.$target_proxy;
$mysqli->close();
$headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36';
if ($headers) {
foreach ($headers as $key => $header) {
$result[] = $key . ":" . $header;
}
$headers = join("\r\n", $result);
}
$aContext = [
'http' => [
'proxy' => $proxy,
'request_fulluri' => true,
//'method' => $post ? 'POST' : 'GET',
//'content' => http_build_query($post),
'header' => $headers,
],
];
$cxContext = stream_context_create($aContext);
$server_output = file_get_contents($url, False, $cxContext);
preg_match('#\d{3}#', $http_response_header[0], $code);
//var_dump($server_output, $code[0], $aContext, $url); exit();
return ['server_output' => $server_output, 'httpcode' => $code[0]];
}
抱歉,我找到了一个解决方案,我所做的全部更改都是在$ aContext数组中将键“ http”更改为“ https”,并且可以正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.