Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curl -i
- -X POST
- -H 'Content-Type: application/x-www-form-urlencoded'
- -u SwVl97HRUgWHutJGzO1wt1JMjI5JVV62:SgnyQAA8ap0pPcFf
- -d 'grant_type=password&username=user&password=pass'
- https://api.test.com/identity/v1-sandbox/token
- $params = array(
- "client_id" => "SwVl97HRUgWHutJGzO1wt1JMjI5JVV62",
- "client_secret" => "SgnyQAA8ap0pPcFf",
- "username" => "user",
- "password" => "pass",
- "grant_type" => "password");
- $curl = curl_init($endpoint);
- curl_setopt($curl, CURLOPT_HEADER, true);
- curl_setopt($curl, CURLINFO_HEADER_OUT, true);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, urlencode('user').':'.urlencode('pass'));
- // Remove comment if you have a setup that causes ssl validation to fail
- //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $postData = "";
- //This is needed to properly form post the credentials object
- foreach($params as $k => $v)
- {
- $postData .= $k . '='.urlencode($v).'&';
- }
- $postData = rtrim($postData, '&');
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
- echo "Performing Request...";
- $json_response = curl_exec($curl);
- //print_r($json_response);
- print_r(curl_getinfo($curl));
- {
- "code":"401.01.001",
- "error":"unauthorized",
- "message":"Unauthorized - Please check your credentials."
- }
- [url] => https://api.test.com/identity/v1-sandbox/token
- [content_type] => application/json
- [http_code] => 401
- [header_size] => 166
- [request_size] => 314
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement