4

I've got a project in front of me that requires me to build a Soap Client in PHP and pass with the call/request a basic authorization. The client's WSDL doesn't specify a header. This is throwing me off because the basic authorization is needed to access the API in order to use the webservice (a simple user lookup).

This is my code:

<?php
try {
$fullname = "Joe Smith";
$zipcode = "33149";
$session = "1a2b3c4d5e6f";

$client = new SoapClient('example.wsdl', array('location'=>'https://webservice/location', 'username'=>"Green", 'password'=>"tearocks"));

$search = $client->userSearch($session, $fullname, $zipcode); print $search; } catch (SoapFault $e) { echo $e->faultstring; } ?>

The result displays "Unauthorized Request", a 401 error. I've gone through the php.net manual and various ebooks without avail. Any thoughts?

1 Answer 1

4

Try passing "login" instead of "username" according to the docs that's what is used.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. I did pass login but my result is still 'unauthorized request'. Since this is ultimately passing XML, would trying SimpleXML work for a Soap web service?
@aethon try print $client->__getLastResponseHeaders; see what the real headers are. In your options you have to first enable 'trace' = true, before the above method will work.
that would return null since the wsdl doesn't specify headers for the request or response. I did try __getLastResponse though but that returne null too.
@aethon as I said in my last comment. In your options you have to first enable 'trace' = true, before the above method will work. According to the docs those functions don't return anything unless you enable it first.
This is the right answer, basic authorization is using HTTP authentication and actually has nothing to do with SOAP headers or the body of the request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.