带有PORT的URL中的PHP file_get_contents

时间:2012-12-21 12:51:10

标签: php

我正在尝试使用PHP function file_get_contents()。但我尝试打开的URL使用端口,例如:

file_get_contents("http://212.21.323.32:8010")

我无法打开此网址,我该怎么做?

1 个答案:

答案 0 :(得分:3)

我个人使用cURL并使用CURLOPT_PORT设置您要连接的端口。

<?php
$cURL = curl_init('http://www.google.co.uk'); //Initialise cURL with the URL to connect to
curl_setopt($cURL, CURLOPT_PORT, 80); //Set the port to connect to
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); //Get cURL to return the HTML from the curl_exec function

$HTML = curl_exec($cURL); //Execute the request and store the result in $HTML

echo $HTML; //Output the HTML
?>
相关问题