14.8.1. ProblemYou need to authenticate your SOAP requests using HTTP Basic Authentication. 14.8.2. SolutionPass a username and password in via the options array by setting the login and password keys: $options = array('login' => 'elvis', 'password' => 'the-king'); $client = new SOAPClient('http://www.example.com/service.wsdl', $options); 14.8.3. DiscussionThere are a number of ways to handle authentication within SOAP requests. A few popular ways are HTTP Basic Authentication, placing data inside the SOAP header, and using the WS-* specifications, including WS-Security. To make ext/soap add HTTP Basic Authentication credentials to every request, pass your username and password in as options when you create the SOAP client: <?php $options = array('login' => 'elvis', 'password' => 'the-king'); $client = new SOAPClient('http://www.example.com/service.wsdl', $options); ?> Now every request will have an additional HTTP header of Authorization. If your service requires data set in the SOAP request header, see Recipe 26.1 for details on handling that. As of this writing, you cannot use any XML Security specifications with ext/soap. However, Rob Richards is working on it. For more information, check out http://www.cdatazone.org/index.php?/archives/9-WSSE-and-extsoap.html. 14.8.4. See AlsoRecipe 15.8 for handling SOAP authentication in a SOAP server. |