【postman&curl】浏览器、 postman操作和cur
Postman很多公司测试代码的一个常用工具,掌握其用法,对我们接口的测试有很大的帮助。
一、将postman的请求转成cURL
1. 构造postman请求,点击 Code
![](https://img.haomeiwen.com/i12979420/263294de7d3405a8.png)
2. copy cURL 的请求链接
默认是使用长格式选项
![](https://img.haomeiwen.com/i12979420/f85fe1efb445d817.png)
设置使用短格式选项
![](https://img.haomeiwen.com/i12979420/a01df48dc33f13ce.png)
![](https://img.haomeiwen.com/i12979420/c23105ecaf9b97a4.png)
![](https://img.haomeiwen.com/i12979420/42e50e851fd22e9c.png)
3. 在命令行执行
使用长格式选项
![](https://img.haomeiwen.com/i12979420/52306934c73fc92e.png)
使用短格式选项
# curl -X POST \
https://run.mocky.io/v3/e95f6c35-b3c8-43d9-b9ab-f5ce8c1054cf \
-H 'cache-control: no-cache'
![](https://img.haomeiwen.com/i12979420/17747331e6e538be.png)
二、利用Chrome将请求复制为 curl 格式
有时候我们想在 postman 重现浏览器上的某个请求(比如服务器上报错了,需要对该次请求调试),以往可能大家会把 url、参数、header 一个个地复制到 postman 里面,然后点 postman 的 send 发送请求。
Chrome 有个很好用的功能是,把请求复制为 curl 格式。
1.右键请求 -> copy -> copy as curl
![](https://img.haomeiwen.com/i12979420/ceebbb09539a7680.png)
2.现在我们的粘贴板里面有个 curl 格式的请求,接下来我们打开 postman,点击左上角 Import,然后点 Paste Raw Text,然后点击 Import 完成导入
![](https://img.haomeiwen.com/i12979420/fe2cab630ad08f77.png)
3.将请求的完整信息复制到了 postman,发送请求测试
![](https://img.haomeiwen.com/i12979420/3b59148ac75bdaf7.png)
![](https://img.haomeiwen.com/i12979420/1da4b132bb270d74.png)
三、参考
Postman上重现Chrome上请求的小技巧
https://learnku.com/articles/33410
将POSTMAN请求转换为Curl
https://qastack.cn/programming/49432735/converting-a-postman-request-to-curl
Postman 导出 curl命令 到命令行运行 Mac OS
https://blog.csdn.net/zgpeace/article/details/109552780
Postman简单用法以及转cURL等命令的正确姿势
https://blog.csdn.net/w605283073/article/details/94902637
Postman生成curl命令和request
https://blog.51cto.com/thinklili/2344301
postmanlabs/postman-code-generators
https://github.com/postmanlabs/postman-code-generators