目前,我可以成功执行我的邮递员请求以获取我的令牌。我正在使用这些参数:
-标题中的基本授权
现在,我希望以请求前脚本的形式获取此请求(并使用环境变量作为令牌)。
这里是脚本:
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
。
怎么了?
谢谢
您可以将data
部分更改为类似的内容?
body:{
mode:"urlencoded",
urlencoded:[
{
key:"grant_type",
value:"password"
},
{
key:"username",
value:"admin"
},
{
key:"password",
value:"secret"
}
]
}
pm.sendRequest()
示例的丰富资源可以找到here