【发布时间】:2019-10-09 13:22:55
【问题描述】:
我已经在 StackOverflow 中挖掘了几个小时,但我仍然无法解决这个问题:(
我想使用 Curl 发出 POST 请求以获取 Auth 令牌,但即使我:
- 确保
extension=php_curl.dll未被注释掉 - 尝试了不同版本的 PHP
- 已下载固定 curl 扩展并替换它 (reference)
我的代码:
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);
}
有人可以帮我解决这个问题吗?
【问题讨论】:
-
我已经尝试了所有的建议
-
@MasivuyeCokile 这不是重复的。 Y_Lakdime 已经尝试过该帖子中提供的解决方案,但都没有奏效。这就是他创建新帖子的原因
-
@Y_Lakdime 你有没有解决这个问题?我在 2022 年今天遇到了同样的问题。我正在使用 WAMPServer 和 PHP 7.4.26