Postman深入解析之-pm.sendRequest

话不多说,直接上干货
postman 官方文档:https://learning.getpostman.com/

在很多请求之前都需要先获取token,本文以OAuth 2.0为例,

  1. 在header标签栏加上 Bearer {{oa2_token}}

  2. 进入Pre-Request Script,

    const client_id = “FGlZYYrUCAFm3rJv86pn5N1dFGilU8lL”;
    const client_secret = “4ArhUB0o1faSDGNv”;
    const basic_token = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(client_id + “:” + client_secret));

    const regRequest = {
    url: ‘your URL’,
    method: ‘POST’,
    header: [‘Content-Type: application/x-www-form-urlencoded’,
    'Authorization:Basic ’ + basic_token],
    body:
    {
    // mode: ‘raw’, // 使用raw(原始)格式
    // raw: JSON.stringify({ grant_type: ‘client_credentials’ }) //要将JSON对象转为文本发送
    mode: ‘urlencoded’,
    urlencoded: [{
    “key”: “grant_type”,
    “value”: “client_credentials”,
    }]
    }
    };

    pm.sendRequest(regRequest, function (err, response) {
    console.log(response.json())
    pm.variables.set(“oa2_token”,response.json().access_token);
    });

    // postman.setNextRequest(“next_request_name”);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值