请求正文必须包含以下参数:'grant_type'...但我把它放在正文中

Ask*_*ous 2 httprequest node.js oauth-2.0 npm-request microsoft-graph-api

grant_type按照文档所示将参数放入请求正文中,但 Microsoft Graph 仍然抱怨它不存在;

const tokenRequestBody = [
    "grant_type=client_credentials",
    "scope=https%3A%2F%2Fgraph.microsoft.com%2F.default",
    `client_secret=${config.appClient.password}`
].join("&");

request.post(
    {
        url: tokenRequestUrl,
        json: true,
        headers: {
            "content-type": "application/application/x-www-form-urlencoded"
        },
        body: tokenRequestBody
    },
    (err, req, body) => {
        console.log(body.error_description); 
        // Logs: The request body must contain the following parameter: 'grant_type'.

    }
);
Run Code Online (Sandbox Code Playgroud)

Ask*_*ous 5

我想到了。我不得不使用form而不是body请求节点模块。