从Web服务器获取CURL错误“连接被拒绝”,但从localhost运行良好

时间:2017-09-14 19:56:37

标签: php curl

当我尝试从本地服务器运行我的脚本时,它可以工作,但无法从Web服务器运行。

我的剧本:

      $url="http://91.101.61.111:91/SendRequest/?mobile=9999999999&id=11011&reqref=501";
      $request_timeout = 60;
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_TIMEOUT, $request_timeout);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $request_timeout);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $output = curl_exec($ch);
      $curl_errorno = curl_errno($ch);
      $curl_error = curl_error($ch);
      $getserver= curl_getinfo($ch);
      $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch); 

$response = preg_split("/[\s]+/", $output); 
$rstatus = $response[0]." ".$response[1];

if ($rstatus == "REQUEST ACCEPTED")
{
    $raccepted = preg_match('/([\w\s]+) your ref=([\d]+) system_reference=([\w]+)/', $output, $matches);
    $status = $matches[1];  
    $myref = $matches[2];  
    $sysref = $matches[3];
    echo "Status is $status, My Ref ID is $myref, Mars Ref ID is $sysref";  
}
elseif ($rstatus == "REQUEST ERROR")
{
    $rerror = preg_match('/([\w\s]+) errorno=([\d]+);your ref=([\d]+);system_reason=([\w\s]+)/', $output, $matches);
    $status = $matches[1];
    $errorno = $matches[2]; 
    $myref = $matches[3];  
    $sysref = $matches[4];
    echo "Status is $status, Error No is $errorno, My Ref ID is $myref, Mars Message is $sysref";   
}
    echo "<br/><br/>";
    echo "Output: ".$output;
    echo "<br/><br/>";
    echo "Curl HTTP Response Code: ".$httpcode;
    echo "<br/><br/>";
    echo "Curl Error Code: ".$curl_errorno;
    echo "<br/><br/>";
    echo "Curl Error: ".$curl_error;

请注意91.101.61.111是我的静态IP我在端口91上安装了调制解调器。我需要使用上面的脚本向我的调制解调器发送请求。

当我尝试从本地pc服务器(localhost / script.php)运行脚本时,它运行良好。但是当我尝试从我的网络服务器(mywebsite.com/script.php)运行它时,我得到了脚本的响应:

Output: 
Curl HTTP Response Code: 0  
Curl Error Code: 7 
Curl Error: Failed to connect to 59.92.77.151 port 91: Connection refused

我的两台服务器上都没有阻止任何IP。没有防火墙。仍然连接被拒绝。

请帮忙!

OS on Web Server: Linux
OS on Remote Server: Windows
Web Server:Apache

0 个答案:

没有答案