PHP Curl on 81 port

一个人想着一个人 提交于 2019-11-28 08:25:53

问题


I have locally set 2 Apache Server on Port 80 and port 81 using XAMPP. Iam successfully able to access them through my browser. Currently the URL can be accessed at

http://27.4.198.225/ncmsl/check.php 

and

http://27.4.198.225:81/ncmsl/check.php. 

When I try to write a simple curl code for them

$ch=curl_init();                    
$url = "http://27.4.198.225/ncmsl/check.php";
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
curl_close($ch);

It works perfectly fine for server at port 80 but doesn't work for server at port 81, i.e.

$ch=curl_init();                    
$url = "http://27.4.198.225:81/ncmsl/check.php";
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
curl_close($ch);

What could be the possible reason? I have tried using CURLOPT_PORT but that also doesn't work

These URL are LIVE URL. Can anybody check whether they are successfully able to access them using thei own CURL code on their own network


回答1:


Try this

curl_setopt ($ch, CURLOPT_PORT , 81);

Update code:-

see this URL:- php curl problem

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'http://27.4.198.225:81/ncmsl/check.php');
$store = curl_exec ($ch);
echo substr($store, 1);
curl_close ($ch);



回答2:


Take a look at CURLOPT_PORT in the manual for curl_setopt()




回答3:


Use this one for specify port,

curl_setopt($ch, CURLOPT_PORT, 81);



回答4:


Try this:

curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);


来源:https://stackoverflow.com/questions/12296606/php-curl-on-81-port

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!