邮递员获得令牌的预请求不起作用

问题描述 投票:2回答:1

目前,我可以成功执行我的邮递员请求以获取我的令牌。我正在使用这些参数:

-标题中的基本授权

-和这个身体-enter image description here

现在,我希望以请求前脚本的形式获取此请求(并使用环境变量作为令牌)。

这里是脚本:

pm.sendRequest({
    url: 'http://localhost:8084/oauth/token',
    method: 'POST',
    header: {
        'Authorization':'Basic Y2xpZW50OnBhc3N3b3Jk',
        'content-type': 'application/x-www-form-urlencoded'
    },
    data:{
        'password':'secret',
        'username':'admin',
        'grant_type':'password'
    }
}, (err, res) => pm.environment.set("token", res.json().access_token));

不适用于响应:Full authentication is required to access this resource

怎么了?

谢谢

javascript spring-security postman urlencode
1个回答
1
投票

您可以将data部分更改为类似的内容?

body:{
   mode:"urlencoded",
   urlencoded:[
      {
         key:"grant_type",
         value:"password"
      },
      {
         key:"username",
         value:"admin"
      },
      {
         key:"password",
         value:"secret"
      }
   ]
}

pm.sendRequest()示例的丰富资源可以找到here

© www.soinside.com 2019 - 2024. All rights reserved.