У меня возникли проблемы с использованием прокси-маршрута с file_get_contents
. Когда я использую его с cURL
, он работает, но не с этим кодом:
$headers = array('Content-Type: text/xml');
$url = "http://google.com/";
$proxy = 'http://xx.xxx.xxx.xxx:443';
$opts = [
"http" => [
'proxy' => $proxy,
"method" => "POST",
"header" => implode("\r\n", $headers),
'timeout' => 500,
"content" => $request,
],
];
$stream_context = stream_context_create($opts);
$data = file_get_contents($url, false, $stream_context);
return $data;
Проблема в том, что этот не попадает на мой прокси-сервер первым , а идет прямо на google.com.
когда я использую этот код с cURL, он отлично работает:
$handle = curl_init();
$url = "http://google.com";
$proxy = 'xx.xxx.xxx.xxx:443';
// Set the url
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_PROXY, $proxy);
$output = curl_exec($handle);
curl_close($handle);
echo $output;
Может кто-нибудь увидеть, в чем проблема?