请求体必须包含以下参数:'grant_type'...但是我把它放在了body中

The request body must contain the following parameter: 'grant_type'... but I put it in the body

我按照文档所示将 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'.

    }
);

我明白了。对于请求节点模块,我不得不使用 form 而不是 body