【问题标题】:Postman pre-request to get token doesn't work邮递员预先请求获取令牌不起作用
【发布时间】:2020-09-18 00:51:29
【问题描述】:

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

-标题中的基本授权

-还有这个身体 -

现在我想将此请求作为预请求脚本(并为令牌使用环境变量)。

这是脚本:

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】:

    您可以将data 部分更改为这样的内容吗?

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

    pm.sendRequest() 示例的一个很好的资源可以找到here

    【讨论】:

    • 我当然可以,而且我做到了,而且它有效。非常感谢。
    猜你喜欢
    • 2020-12-05
    • 2018-02-05
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    相关资源
    最近更新 更多