php中的肥皂版本不匹配

时间:2016-06-08 12:04:23

标签: php curl soap request

以下是我的请求详情

$output='<xml version="1.0" encoding="utf-16"?>  
 <opertaion xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    
 <foo xmlns="http://www.w3schools.com">12</foo>    
<boo xmlns="http://www.w3schools.com">15</boo>   
 <bar xmlns="http://www.w3schools.com">test value</bar>   
 </opertaion>';


 $url='http://www.url.com';
    $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "Content-length: ".strlen($output),
                ); //SOAPAction: your op URL
        // PHP cURL  for https connection with auth
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $output); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

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

       echo $response;
  

皂:VersionMismatchSystem.Web.Services.Protocols.SoapException:   可能的SOAP版本不匹配:信封命名空间是意外的。   期待http://schemas.xmlsoap.org/soap/envelope/。在系统。

我在做什么错误?

1 个答案:

答案 0 :(得分:1)

如果您想使用cURL进行SOAP调用,则需要确保您的请求正文是正确的SOAP请求。

您的XML需要使用SOAP标记包装,如下所示:

let data : NSData = stringToSend.dataUsingEncoding(NSUTF8StringEncoding)!

if positionCharacteristic != nil {

self.polarH7HRMPeripheral.writeValue(data, forCharacteristic: positionCharacteristic, type: .WithoutResponse)

self.polarH7HRMPeripheral.setNotifyValue(true, forCharacteristic: positionCharacteristic)


}

您也可以使用SoapClient: http://php.net/manual/en/soapclient.soapclient.php