我试图使用PHP file_get_contents为IP。例:
echo file_get_contents("1.22.22:2334/pay");
但是,PHP和Curl不会返回IP地址的内容,我将如何进行此操作?
非常感谢你。
您应该使用curl,因为file_get_contents
需要在php.ini配置文件中启用allow_url_fopen
(情况并非总是如此)。
只有卷曲和IP才应该像:
// create curl resource
$ch = curl_init();
// headers for ip only
$headers = array("Host: www.myfaketopsite.com");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "https://1.22.22:2334/pay");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
部分答案来自:PHP cURL connect using IP address instead domain name