Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. curl -i
  2. -X POST
  3. -H 'Content-Type: application/x-www-form-urlencoded'
  4. -u SwVl97HRUgWHutJGzO1wt1JMjI5JVV62:SgnyQAA8ap0pPcFf
  5. -d 'grant_type=password&username=user&password=pass'
  6. https://api.test.com/identity/v1-sandbox/token
  7.  
  8. $params = array(
  9. "client_id" => "SwVl97HRUgWHutJGzO1wt1JMjI5JVV62",
  10. "client_secret" => "SgnyQAA8ap0pPcFf",
  11. "username" => "user",
  12. "password" => "pass",
  13. "grant_type" => "password");
  14.  
  15. $curl = curl_init($endpoint);
  16. curl_setopt($curl, CURLOPT_HEADER, true);
  17. curl_setopt($curl, CURLINFO_HEADER_OUT, true);
  18. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  19. curl_setopt($curl, CURLOPT_POST, true);
  20. curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
  21. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  22. curl_setopt($curl, CURLOPT_USERPWD, urlencode('user').':'.urlencode('pass'));
  23.  
  24. // Remove comment if you have a setup that causes ssl validation to fail
  25. //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  26. $postData = "";
  27.  
  28. //This is needed to properly form post the credentials object
  29. foreach($params as $k => $v)
  30. {
  31. $postData .= $k . '='.urlencode($v).'&';
  32. }
  33.  
  34. $postData = rtrim($postData, '&');
  35.  
  36. curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
  37. echo "Performing Request...";
  38.  
  39. $json_response = curl_exec($curl);
  40. //print_r($json_response);
  41.  
  42. print_r(curl_getinfo($curl));
  43.  
  44. {
  45. "code":"401.01.001",
  46. "error":"unauthorized",
  47. "message":"Unauthorized - Please check your credentials."
  48. }
  49.  
  50. [url] => https://api.test.com/identity/v1-sandbox/token
  51. [content_type] => application/json
  52. [http_code] => 401
  53. [header_size] => 166
  54. [request_size] => 314
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement