[英]PHP/Curl request is not working
phpinfo(); phpinfo(); function shows that curl is enabled. 功能显示已启用卷曲。 dll statements are also uncommented in the .ini file. .ini文件中也不会注释dll语句。 Still the curl request is not working. 仍然没有卷曲请求。
<?php
//step1
$cSession = curl_init();
//step2
curl_setopt($cSession,CURLOPT_URL,"http://www.google.com");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
//step3
$result=curl_exec($cSession);
if(curl_errno($cSession)){
echo 'Curl error: ' . curl_error($cSession);
}
//step4
curl_close($cSession);
//step5
echo $result;
?>
This code shows the error: 此代码显示错误:
Curl error: Failed to connect to 192.168.1.1 port 8080: Timed out 卷曲错误:无法连接到192.168.1.1端口8080:超时
Can you check firewall on that site. 您可以检查该站点上的防火墙吗? I am sure that firewall on that site is blocking traffic to IP address of your server. 我确定该站点上的防火墙阻止了到您服务器IP地址的流量。
Check the DNS resolution as well. 还要检查DNS解析度。 Better yet, try to ping 192.168.1.1 from the machine that is not working. 更好的是,尝试从无法运行的计算机上ping 192.168.1.1。 Also wget https://192.168.1.1:8080 (from the machine that is not working) will give you detailed error message. 另外wget https://192.168.1.1:8080 (从无法运行的机器上)将为您提供详细的错误消息。
use this code 使用此代码
function curl($url) {
$ch = curl_init(); // Initialising cURL
curl_setopt($ch, CURLOPT_URL, $url); // Setting cURL's URL option with the $url variable passed into the function
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
$data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
curl_close($ch); // Closing cURL
return $data; // Returning the data from the function
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.