skip to Main Content

I have been digging in StackOverflow for hours now but I still didn’t manage to resolve this 🙁

I want to do a POST request with Curl to get an Auth token, but even though I:

  • Made sure extension=php_curl.dll is not commented out
  • Tried different versions of PHP
  • Downloaded the fixed curl extension and replaced it (reference)

My code:

  function getToken() {
    echo "start gettoken";

    $jsonStr = http_build_query(Array(
        "client_id" => "***",
        "scope" => "https://graph.microsoft.com/.default",
        "client_secret" => "***",
        "grant_type" => "client_credentials"
    ));
    $headers = Array("Content-Type: application/x-www-form-urlencoded");

    $ch = curl_init("https://login.microsoftonline.com/***.onmicrosoft.com/oauth2/v2.0/token");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $token = curl_exec($ch);
    echo "test after curl";
    var_dump($token);
    echo $token;
    return $token;

    curl_error($ch);


}

Can someone please help me with this issue?

2

Answers


  1. Enable php_curl.dll extension, seems like it’s disabled. You can verify it by using

    echo phpinfo();
    

    or directly access the php.ini to check if it’ disabled.

    stop wamp server, open php.ini, search for this extension=php_curl.dll and uncomment it.

    Save the file and restart the server.

    Login or Signup to reply.
  2. For me this did the trick: http://www.phpmind.com/blog/2011/02/how-to-enable-curl-in-wamp/

    1) Close WAMP (if running)

    2) Navigate to WAMPbinphp(your version of php)

    3) edit php.ini

    4) Search for curl, uncomment extension=php_curl.dll

    5) Navigate to WAMPbinApache(your version of apache)bin

    6) edit php.ini

    7) Search for curl, uncomment extension=php_curl.dll

    8 ) Save both

    9) Restart WAMP

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search