正文
postman使用动态token发post请求小结
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
最近使用postman做接口测试,感觉挺好用的。
测试中,每次post请求都要携带一个token,token是通过get请求得来的,动态变化的,并且token有有效期的限制。为了避免重复获取token来手工修改给post请求赋值:
1.把token做成 环境变量 ,这样多个post请求可以复用
在post请求中使用 环境变量 ,携带token信息
2.发送get请求获取当前可用token之后, 在Tests中给环境变量赋值 ,这样避免了token过期后,要手工发get,然后再手工修改环境变量的麻烦(官方文档对pm.response对象的解释也有限,摸索了好久!)
官方文档:
https://learning.getpostman.com/docs/postman/scripts/test_examples/
https://learning.getpostman.com/docs/postman/scripts/test_scripts/