【问题标题】:Curl not able to Connect to host while Curl is enabled on Server在服务器上启用 Curl 时,Curl 无法连接到主机
【发布时间】:2016-05-08 07:48:47
【问题描述】:

我正在使用 curl 调用 Web 服务,它在 localhost 中运行良好,但是当我在我的实时网站上使用相同的脚本调用它时会输出错误:

无法连接到主机

这是我的 Live 网站 curl 设置

 $soap_request = '<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <InsertData xmlns="http://exampleServiceSite:6265">          
      <remarks>No Remarks</remarks>
      <insuranceValue>0</insuranceValue>
    </InsertData>
    </soap:Body>
    </soap:Envelope>';

$header = array(
    "POST /Service1.asmx HTTP/1.1",
        "Content-type: text/xml;charset=\"utf-8\"",
        "Accept: text/xml",
        "Cache-Control: no-cache",
        "Pragma: no-cache",
        "SOAPAction: \"http://exampleServiceSite:6265/InsertData\"",
        "Content-length: ".strlen($soap_request),
    );

    $soap_do = curl_init();
        curl_setopt($soap_do, CURLOPT_URL,            "http://exampleServiceSite:6265/" );
        curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
        curl_setopt($soap_do, CURLOPT_POST,           true );
        curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
        curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);
        $result = curl_exec($soap_do);
        var_dump($result);

【问题讨论】:

  • 需要设置代理吗? 6265端口是否开放?
  • @David 我希望使用的网络服务来自第 3 方,所以我无法检查该第三方网络服务的端口,还是您的意思是我需要检查我的实时网络服务器上的 6265 端口?
  • 端口 6265 需要两边都打开。如果将 url 更改为 google.com 会怎样?您仍然无法连接到主机吗?如果是,请尝试设置 curl 代理。
  • @David 与 google.com 一起工作正常,即加载 google.com 页面不会出现任何错误
  • 抱歉,我帮不了你。变化是只允许传统端口。请咨询服务器的支持团队

标签: php web-services curl localhost


【解决方案1】:

您是否可以通过 SSH 访问您的开发机器?

如果是这样,请打开一个 SSH 会话并尝试以下操作:

&gt;telnet exampleServiceSite 6265

你遇到过这样的事情吗?

Trying 62.253.72.158...
Connected to google.com.
Escape character is '^]'.

【讨论】:

  • 你也可以尝试从命令行curl,这可能会比telnet显示更多信息:curl -v http://server:6265
  • 无权访问 SSH,它的共享主机具有有限的 cpanel 访问权限
猜你喜欢
  • 2011-08-22
  • 2013-07-31
  • 1970-01-01
  • 2020-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 2014-01-25
相关资源
最近更新 更多