PHP curl with soap错误:无法处理没有有效操作参数的请求



我在php中通过curl发送一个soap请求,我得到了这个响应:

客户端无法处理没有有效操作参数的请求。请提供有效的soap操作。

SOAP XML:

$url="http://www.site.com/soap.asmx";
$user = "test";
$password = "test";
$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:Header>
    <Routing xmlns="www.site.com">
      <Login>test</Login>
      <Password>testy</Password>
   </Routing>
  </soap:Header>
  <soap:Body>
</soap:Body>
</soap:Envelope>';
旋度:

 $soapme = curl_init(); 
           curl_setopt($soapme, CURLOPT_URL,            $url );   
            curl_setopt($soapme, CURLOPT_CONNECTTIMEOUT, 10); 
            curl_setopt($soapme, CURLOPT_TIMEOUT,        10); 
            curl_setopt($soapme, CURLOPT_RETURNTRANSFER, true );
            curl_setopt($soapme, CURLOPT_SSL_VERIFYPEER, false);  
            curl_setopt($soapme, CURLOPT_SSL_VERIFYHOST, false); 
            curl_setopt($soapme, CURLOPT_POST,           true ); 
            curl_setopt($soapme, CURLOPT_POSTFIELDS,    $post_string); 
            curl_setopt($soapme, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) )); 
            curl_setopt($soapme, CURLOPT_USERPWD, $user . ":" . $password);
            curl_setopt($soapme, curlOPT_VERBOSE, 1); 
            curl_exec($soapme);

如果不能看到SOAP Web服务所期望并由WSDL定义的实际消息和操作类型,那么我可以打赌,您的Headers行缺少SOAP 1.1 SOAPAction标头:

curl_setopt($soapme, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'SOAPAction: "Routing"', 'Content-Length: '.strlen($post_string) )); 

请注意,我将SOAPAction命名为Routing,但它实际上可以是任何东西,取决于Web服务期望和WSDL定义的内容。

最新更新