Issue
I'm trying to call a URL from PHP via cURL, but no response from server.
Following is my URL:
$url = 'https://id:[email protected]/oauth/token \ -X POST \ -d "grant_type=client_credentials&scope=manage_project:test"';
Curl code:
$auth = curl_init($url);
curl_setopt($auth, CURLOPT_POST, true);
curl_setopt($auth, CURLOPT_HEADER, false);
curl_setopt($auth, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($auth);
curl_close($auth);
print_r($response);
When I execute the same URL in terminal get response from server. What's wrong in cURL code?
Solution
Using the documentation - this should work. Note the correct URL and passing the post parameters correctly
$auth = curl_init("https://auth.sphere.io/oauth/token");
curl_setopt($auth, CURLOPT_POST, true);
curl_setopt($auth, CURLOPT_HEADER, false);
curl_setopt($auth, CURLOPT_RETURNTRANSFER, true);
curl_setopt($auth,CURLOPT_POST, 2);
curl_setopt($auth,CURLOPT_USERPWD, "id:secret");
curl_setopt($auth,CURLOPT_POSTFIELDS, "grant_type=client_credentials&scope=manage_project:test");
$response = curl_exec($auth);
curl_close($auth);
print_r($response);
Answered By - Ed Heal Answer Checked By - Clifford M. (WPSolving Volunteer)