2.Post x-www-form-urlencoded格式请求
const loginRequest = {
url: ‘127.0.0.1:8000/member/api/login/‘,
method: ‘POST‘,
header: {
‘Content-Type‘:‘application/x-www-form-urlencoded‘,
‘Accept‘: ‘application/json‘
},
body: {
mode: ‘urlencoded‘,
urlencoded:[{key:"user_name", value:"sunwk10005"},
{key:"password", value:"a1122334"}
],
}
};
3.get请求
const url = ‘http://115.28.108.130:5000/api/user/getToken/?appid=136425‘;
// 发送get请求
pm.sendRequest(url, function (err, res) {
console.log(err ? err : res.text()); // 控制台打印请求文本
});
//同样可以配合pm.environment.set(key:value)来将响应中的数据保存到环境变量中以供请求使用
4.XML格式请求
//构造请求
const demoRequest = {
url: ‘http://httpbin.org/post‘,
method: ‘POST‘,
header: ‘Content-Type: application/xml‘, // 请求头种指定内容格式
body: {
mode: ‘raw‘,
raw: ‘<xml>hello</xml>‘ // 按文本格式发送xml
}
};
//发送请求
pm.sendRequest(demoRequest, function (err, res) {
console.log(err ? err : res.json());
});