简体   繁体   中英

php curl with soap error: unable to handle request without valid action parameter

I am sending a soap request via curl in php, and I get this response:

Client Unable to handle request without a valid action parameter. Please supply a valid soap action.

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>';

CURL:

 $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);

Without being able to see the actual message and action types expected by the SOAP Web Service and defined by the WSDL, then I can wager a bet that your Headers line is missing the SOAP 1.1 SOAPAction header:

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

Please note, I called the SOAPAction Routing but it really could be anything, depending as mentioned, on what the Web Service expects and WSDL defines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM