簡體   English   中英

用curl soap xml調用PHP中的卷曲超時

[英]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 )發布,它顯示帶有請求標頭

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

似乎在網上出現語法錯誤

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

它應該是

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

解決此問題后,代碼對我有用。

LE:最后,問題出在ISP過濾/阻止了8084端口。 因此,“連接超時”就是因為這個原因。

感謝Marcel Preda,他們為我縮小了范圍。 原來代碼很好(除了一個語法錯誤),但是它是我的服務提供商的阻止端口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM