dtdtdg Posted May 7, 2014 Share Posted May 7, 2014 (edited) I'm connecting up to an API via the following method however it is returning a "unauthorized" response. This is to validate the user credentials and return a response.I am trying to connect to a Way-2 with LDAP although I'm not a C# person. <?php //error_reporting(E_ALL); //ini_set('display_errors', '1'); $service_url = 'http://www.myurl.com/webservices/getuser'; $curl = curl_init($service_url); $curl_post_data = array( "username" => 'mywebservice', // "password" => 'wspass', // "UserProfileID" => 'weiuYhJxmeoQLsKvviPNzr==', "Name" => 'John' ); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); $curl_response = curl_exec($curl); curl_close($curl); echo "Data: "; $xml = new SimpleXMLElement($curl_response); echo $xml; ?> In essence it should connect up to the webservice with the username and password as specified above, then a POST request is made to the $service_url with the following parameters: Request XML <xml> <UserProfileID>weiuYhJxmeoQLsKvviPNzr==</UserProfileID> <Name>John</Name> </xml> Example of Valid Response XML <xml> <UserProfileID>weiuYhJxmeoQLsKvviPNzr==</UserProfileID> <Name>John</Name> <ProfileImage>http://www.myurl.com/profile_image/dfkjd.png</ProfileImage> </xml> How can I modify my PHP accordingly to connect properly and get this working, and actually responding with the valid XML response for that user? Thanks Edited May 7, 2014 by dtdtdg Quote Link to comment Share on other sites More sharing options...
requinix Posted May 7, 2014 Share Posted May 7, 2014 You have to send actual XML. According to your example, which I'm very sure does not show all the information required to make this work, $curl_post_data = <<<XML <xml> <UserProfileID>weiuYhJxmeoQLsKvviPNzr==</UserProfileID> <Name>John</Name> </xml> XML; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.