我们将从Guzzle3迁移到Guzzle6。我写了一个过程来验证和访问Azure Management API,它在Guzzle3中工作得很好。然而,我不知道如何让它在Guzzle6中工作。目的是获取访问令牌,然后在对Azure管理API的后续请求中使用。
原始代码:
$client = new Guzzle\Http\Client();
$request = $client->post("https://login.microsoftonline.com/{$tenant_id}/oauth2/token",
Array(
'Accept' => 'application/json',
),
Array(
'grant_type' => 'client_credentials',
'client_id' => $application_id,
'client_secret' => $application_secret,
'resource' => 'https://management.core.windows.net/',
)
);
$response = $request->send();
$body = $response->getBody(true);我正在编写的新代码:
$client = new GuzzleHttp\Client();
$response = $client->request(
'POST',
"https://login.microsoftonline.com/{$tenant_id}/oauth2/token",
Array(
GuzzleHttp\RequestOptions::JSON => Array(
'grant_type' => 'client_credentials',
'client_id' => $application_id,
'client_secret' => $application_secret,
'resource' => 'https://management.core.windows.net/',
)
)
);我尝试了这么多变种,但都没有成功。对于任何人能提供的任何见解,我将不胜感激。
谢谢!
发布于 2017-06-06 13:17:06
好吧,我想在这里发表帖子有助于引导我对此的想法。我能让它正常工作。对于其他人来说,这是我想出的解决方案:
$client = new GuzzleHttp\Client();
$response = $client->request(
'POST',
"https://login.microsoftonline.com/{$tenant_id}/oauth2/token",
Array(
'form_params' => Array(
'grant_type' => 'client_credentials',
'client_id' => $application_id,
'client_secret' => $application_secret,
'resource' => 'https://management.core.windows.net/',
)
)
);https://stackoverflow.com/questions/44381027
复制相似问题