postman Pre-request Script 发送请求
- 发送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 格式表单
相关推荐
充满诗意的联盟 2020-08-23
Teamomc 2020-06-28
huimeiad 2020-11-23
82387067 2020-11-03
bbccaaa 2020-11-03
ljsfighting 2020-10-31
小马的学习笔记 2020-10-23
chenhaimeimeng 2020-09-15
82387067 2020-08-15
bbccaaa 2020-07-28
ljsfighting 2020-07-28
ljsfighting 2020-07-18
ljsfighting 2020-07-05
Alassad 2020-06-29
pushTop 2020-06-27
curiousL 2020-06-21
Teamomc 2020-06-12