gpt4 book ai didi

php - 如何将 file_get_contents 与代理一起使用?

转载 作者:太空宇宙 更新时间:2023-11-03 14:31:58 27 4
gpt4 key购买 nike

当我将 file_get_contents 与 SSL 和代理一起使用时,出现以下错误:

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number in D:\XAMPP\htdocs\instahu\app\vendor\classes\instagram.php on line 154

Warning: file_get_contents(https://www.instagram.com/explore/tags/test/): failed to open stream: Cannot connect to HTTPS server through proxy in D:\XAMPP\htdocs\instahu\app\vendor\classes\instagram.php on line 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' 并且它有效

关于php - 如何将 file_get_contents 与代理一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52000739/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com