通过CURL用PHP调用soap请求

时间:2019-04-21 06:00:29

标签: php curl soap

这是我需要使用CURL调用的肥皂链接:

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

我需要此功能:

>message name="domainInfoRequest

及其答案:

>message name="domainInfoResponse

但是我不知道怎么称呼它。我看到了其他主题,但是它们没有帮助,所以我编写了以下代码:

    $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.

但这没用!

0 个答案:

没有答案