php中的Soap版本不匹配

php中的Soap版本不匹配,php,curl,soap,request,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>

这是我的申请详情

$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;
$output=
12
15
测试值
';
$url='1http://www.url.com';
$headers=数组(
“内容类型:text/xml;字符集=\“utf-8\”,
“接受:文本/xml”,
“缓存控制:无缓存”,
“Pragma:无缓存”,
“内容长度:”.strlen($output),
); //SOAPAction:您的操作URL
//用于https与auth连接的PHP cURL
$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_超时,10);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_USERPWD,$soapUser.:“$soapPassword);
curl_setopt($ch,CURLOPT_POSTFIELDS,$output);//SOAP请求
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
//转换
$response=curl\u exec($ch);
卷曲关闭($ch);
回音$应答;
soap:VersionMismatchSystem.Web.Services.Protocols.SoapException: 可能的SOAP版本不匹配:信封命名空间意外。 期望。在系统中


我所做的错误是什么?

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

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

<?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>
    <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>
  </soap:Body>
</soap:Envelope>

12
15
测试值
您还可以使用SoapClient:

请您添加有关错误的更多信息,好吗?我可以看到您的输出XML包含一个
标记,而不是
。是否有必要提供SOAPAction?是的,因为SOAPURL(您向其发出请求的url)只是一个包含操作的服务的url。您需要在标题中指定操作,请检查以下答案: