通过CURL在PHP中调用soap请求

This is a soap link that I need to call with CURL:

http://webservice-ip1.systemnic.net/index.php?wsdl

I need this function:

>message name="domainInfoRequest

and its answer:

>message name="domainInfoResponse

But I don't know how to call it. I saw other topics but they weren't helpful, so I wrote this code:

    $soapUrl = "http://webservice-ip1.systemnic.net/index.php?wsdl"; // asmx URL of WSDL
    $soapUser = "username";  //  username
    $soapPassword = "password"; // password

    // xml post structure

    $xml_post_string = '<?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>
                            <domainInfo xmlns="http://webservice-ip1.systemnic.net/index.php?wsdl">
                              <api_user>"myusername"</api_user> 
                              <api_pass>"mypass"</api_pass> 
                              <domain>"mydomain"</domain> 
                            </domainInfo >
                          </soap:Body>
                        </soap:Envelope>';   // data from the form, e.g. some ID number

       $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "SOAPAction: http://webservice-ip1.systemnic.net/index.php?wsdl", 
                    "Content-length: ".strlen($xml_post_string),
                ); //SOAPAction: your op URL

        $url = $soapUrl;

        // PHP cURL  for https connection with auth
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // converting
        $response = curl_exec($ch); 
        curl_close($ch);

        // converting
        $response1 = str_replace("<soap:Body>","",$response);
        $response2 = str_replace("</soap:Body>","",$response1);

        // convertingc to XML
        $parser = simplexml_load_string($response2);
        // user $parser to get your data out of XML response and to display it.

But it didn't work!

duankui6150
duankui6150 您应该发送动作函数名称以及标题数组“SOAPAction:systemnic.net/services/#domainInfo”中的标题
一年多之前 回复
doujianchao7446
doujianchao7446 非常感谢,但我的服务器中的soap库非常慢!我不知道为什么!因此我尝试在我的服务器中使用curl而不是soap!
一年多之前 回复
duandu1377
duandu1377 btwphp有一个肥皂库
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐