Jump to content

PHP Restful API authorization error


dtdtdg

Recommended Posts

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 by dtdtdg
Link to comment
Share on other sites

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;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.