有没有办法更改 Postman OAuth 2 客户端凭据请求的内容类型?

问题描述

我正在尝试使用内置工具为我的请求获取 OAuth 2.0 令牌。这在阅读文档时看起来很简单,我是这样设置的:

screenshot from postman request

问题是发送的令牌请求的内容类型为 application/x-www-form-urlencoded。所以我从服务器得到的响应是 415 Unsupported Media Type 我看不到将请求内容类型更改为 application/json方法

screenshot of postman console log

我是否遗漏了什么或者是创建自定义预请求脚本的唯一方法

解决方法

https://github.com/oauthjs/node-oauth2-server/issues/92

application/x-www-form-urlencoded ,是 Oauth 支持的内容类型

https://tools.ietf.org/html/rfc6749#section-4.1.3

如果您想创建 ,您可以使用先决条件脚本,例如:

https://gist.github.com/madebysid/b57985b0649d3407a7aa9de1bd327990

// Refresh the access token and set it into environment variable
pm.sendRequest({
    url:  pm.collectionVariables.get("zoho_accounts_endpoint") + "/oauth/v2/token",method: 'POST',header: {
        'Accept': 'application/json','Content-Type': 'application/x-www-form-urlencoded',},body: {
        mode: 'urlencoded',urlencoded: [
            {key: "client_id",value: pm.collectionVariables.get("zoho_client_id"),disabled: false},{key: "client_secret",value: pm.collectionVariables.get("zoho_client_secret"),{key: "refresh_token",value: pm.collectionVariables.get("zoho_refresh_token"),{key: "grant_type",value: 'refresh_token',disabled: false}
        ]
    }
},function (err,res) {
    pm.collectionVariables.set("zoho_access_token",'Zoho-oauthtoken ' + res.json().access_token);
});

将其更改为 JSON 或您想要的任何内容并将值存储到变量并将其用作承载 {{token}}