![](/img/trans.png)
[英]file_get_contents/curl PHP Function Not Working For IP Address
[英]How to get contents of IP address in PHP
我正在嘗試將PHP file_get_contents用於IP。 例:
echo file_get_contents("1.22.22:2334/pay");
但是PHP And Curl不會返回IP地址的內容,我該怎么做?
非常感謝你。
您應該使用curl,因為file_get_contents
要求在php.ini配置文件中啟用allow_url_fopen
(並非總是如此)。
僅使用curl和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使用IP地址代替域名進行連接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.