在调用 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 条评论

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注

站点统计

  • 文章总数:329 篇
  • 分类总数:20 个
  • 标签总数:193 个
  • 运行天数:1608 天
  • 访问总数:1048267 人次

浙公网安备33011302000604

辽ICP备20003309号