使用 curl soap xml 调用的 php 中的 Curl 超时

Curl timeout in php with curl soap xml call

好吧,我在这件事上焦头烂额。我根本没有使用 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) 发帖,显示请求 headers

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

和body

<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);
    }

似乎是一行语法错误

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

应该是

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

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

LE: 最后发现问题是端口 8084 被 ISP filter/blocked 占用了。所以,"Connection time out"就是因为这个。

感谢 Marcel Preda,他们帮我缩小了范围。事实证明代码没有问题(除了一个语法错误),但它是我的服务提供商阻止的端口。