在调用 http://127.0.0.1:8077/openApi/testMultiDataSource前需调用鉴权接口获取token后设置到该接口请求头中 Authorization。
可以设置prerequest脚本
// Send POST request to get access token
pm.sendRequest({
url: 'https://iam.cccc.com/auth/realms/cfmoto/protocol/openid-connect/token',
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: 'client_id', value: 'ba3333ta'},
{key: 'grant_type', value: 'password'},
{key: 'client_secret', value: 'uksrGZA33333333333338cst'},
{key: 'username', value: 'po33333a'},
{key: 'password', value: '9lp+@o&g2333333'}
]
}
}, function (err, res) {
if (err) {
console.log('Error fetching token:', err);
} else {
// Parse the response and extract access_token
const jsonData = res.json();
const accessToken = jsonData.access_token;
// Update the Authorization header with the token
pm.request.headers.upsert({
key: 'Authorization',
value: accessToken
});
console.log('Authorization header updated with access token');
}
});
0 条评论