0

I'm struggling to construct my cURL request properly.

URL2 works fine. URL1 doesn't. What am I doing wrong?

I've tried removing and replacing the initial '?' on the postfields, but nothign changes. It's got to be something simple :/

Other similar posts like this PHP cURL post fields not working correctly are about slightly different problems.

URL1

$url1="https://....../platform/oauth/request_token";
$client_id="......";
$client_secret="......";
$postfields = "?client_id=".$client_id."&client_secret=".$client_secret."&grant_type=client_credentials";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($ch);
print $result;


Response code: 400
{"error_description":"client_id must be provided","error":"invalid_request"}

URL2

$url2="https://....../platform/oauth/request_token?client_id=".$client_id."&client_secret=".$client_secret."&grant_type=client_credentials";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);


Response code: 200
{"access_token":".....","refresh_token":"....","expires_in":....}
Phil
  • 157,677
  • 23
  • 242
  • 245
Maxcot
  • 1,513
  • 3
  • 23
  • 51

0 Answers0