- 发送get请求
var host = pm.environment.get("host"); const csrfTokenServlet = { url: `https://${host}/{path}?csrfType=test`, method: ‘GET‘ }; pm.sendRequest(csrfTokenServlet, (err, response) => { if (err) { console.log(err); } else { pm.environment.set("csrfToken", response.json()[‘data‘]); console.log(response.json()[‘data‘]) } });
- 发送post请求
# content-type/x-www-form-urlencoded var host = pm.environment.get("host"); var data = { "organCode":"10000065", } const postRequest = { url: `https://${host}/${path}`, method: ‘POST‘, header:‘Content-Type:application/x-www-form-urlencoded‘, body: { mode: ‘x-www-form-urlencoded‘, raw: "organCode=10000062" }}; pm.sendRequest(postRequest, (err, response) => { if (err) { console.log(err); } else { console.log(response.json()); } }); 或者 var host = pm.environment.get("host"); var data = { "organCode":"10000065", } const postRequest = { url: `https://${host}/${path}`, method: ‘POST‘, header:‘Content-Type:application/x-www-form-urlencoded‘, body: { mode: ‘urlencoded‘, urlencoded: "organCode=10000062" }}; pm.sendRequest(postRequest, (err, response) => { if (err) { console.log(err); } else { console.log(response.json()); } }); # content-type/json var data = { "key1":"value1", "key2":"value2",} const echoPostRequest = { url: ‘http://ip:port/XXX, method: ‘POST‘, header:‘Content-Type:application/json‘, body: { mode: ‘raw‘, raw: JSON.stringify(data) }}; pm.sendRequest(echoPostRequest, function (err, res) { console.log(res.json()); });
参考:
postman(六):详解在Pre-request Script中如何执行请求
postman 在pre-request中发送application/x-www-form-urlencoded 格式表单
原文地址:https://www.cnblogs.com/wf0117/p/11971360.html
时间: 2024-10-30 09:41:12