【问题标题】:Curl timeout in php with curl soap xml callphp中的curl超时与curl soap xml调用
【发布时间】:2019-01-15 21:55:51
【问题描述】:

好的,我正在为这个扯头发。我根本没有使用过 PHP WDSL SOAP CURL XML 调用(它们都是单独的,但不是一起的!)并且努力获得响应或有意义的错误。

为了突出这一点,我有一个演示 WDSL 端点 (http://office.keystonesupport.net:8084/DemoSoap/KSDSoap/KhaosKSD.exe/wsdl/IKosWeb?wsdl),如果您坚持使用浏览器,它将以 XML 详细说明所有内容。

然后我尝试编写 PHP 来访问一个不带输入参数的特定操作“GetVersion”

使用 Wizdler (https://chrome.google.com/webstore/detail/wizdler/oebpmncolmhiapingjaagmapififiakb) 发布,它显示带有请求标头

SOAPAction: "urn:IKosWebIntf-IKosWeb#GetVersion"
Content-Type: text/xml; charset="utf-8"

和身体

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
        <Body>
            <GetVersion xmlns="http://tempuri.org/"/>
        </Body>
    </Envelope>

收到回复

<?xml version="1.0"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
        <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS1="urn:IKosWebIntf-IKosWeb">
            <NS1:GetVersionResponse>
                <return xsi:type="xsd:string">8.149.29</return>
            </NS1:GetVersionResponse>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

所以我把它放到了我的脚本中,如下所示。 但它只是给出了 curl 超时错误?

$xml='<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
        <Body>
            <GetVersion xmlns="http://tempuri.org/"/>
        </Body>
    </Envelope>';
 $url='http://office.keystonesupport.net:8084/DemoSoap/KSDSoap/KhaosKSD.exe/wsdl/IKosWeb?wsdl';

    $ch = curl_init();
    $headers = array(
            "Content-type: text/xml;charset=\"utf-8\"",
            "SOAPAction:  \"urn:IKosWebIntf-IKosWeb#GetVersion"",
        );
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
        curl_setopt($ch, CURLOPT_URL,            $url );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt($ch, CURLOPT_POST,           true );
        curl_setopt($ch, CURLOPT_POSTFIELDS,     $xml);
        curl_setopt($ch, CURLOPT_HTTPHEADER,     $headers);


    print_r ($headers);
    echo '<br>';
    echo htmlentities($xml);
    echo '<br>';
    $response = curl_exec($ch);
    if($response === false) {
            $err = 'Curl error: ' . curl_error($ch);
            curl_close($ch);
            print $err;
        }else{
    curl_close($ch);
    var_dump($response);
    }

【问题讨论】:

    标签: php xml curl soap wsdl


    【解决方案1】:

    似乎是因为在线语法错误

     "SOAPAction:  \"urn:IKosWebIntf-IKosWeb#GetVersion"",
    

    应该是

     "SOAPAction:  \"urn:IKosWebIntf-IKosWeb#GetVersion\"",
    

    修复此问题后,代码对我有用。

    LE: 最终发现问题在于 8084 端口被 ISP 过滤/阻止。所以,“连接超时”就是因为这个。

    【讨论】:

    • 你得到什么回应?我进行了更改,但只是得到“Curl 错误:无法连接到 office.keystonesupport.net 端口 8084:连接超时”
    • 它很长,堆栈溢出抱怨“太长了 54059 个字符”。开头为:数组([0] => 内容类型:text/xml;charset="utf-8" [1] => SOAPAction: "urn:IKosWebIntf-IKosWeb#GetVersion")
      <信封 xmlns= "schemas.xmlsoap.org/soap/envelope/&quot;&gt; <身体> <GetVersion xmlns="tempuri.org/&quot;/&gt; </正文> </信封>
      string(54275) "
    • 我认为端口 8084 有问题,可能它在某些路由器/代理上被阻止。从命令行尝试 telnet office.keystonesupport.net 8084 ,如果它有效,您将在最后看到消息 Escape character is '^]'. 。如果它不起作用(端口被阻塞),最后一行将是 telnet: Unable to connect to remote host: Resource暂时不可用
    【解决方案2】:

    感谢 Marcel Preda,他们帮我缩小了范围。结果证明代码很好(除了一个语法错误),但它是来自我的服务提供商的阻塞端口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多