作为一名后端程序员,在服务器调试的过程中,使用curl命令为我们调试接口带来了很多的方便,极大地提高了效率;

如下可以实现Get请求:

curl ' http://baidu.com/userInfo?userId=123&token=iaotjadfaoijtj '
可以实现Post请求:

curl http://baidu.com/userInfo -d '{"userId": 123, "token": "iaotjadfaoijtj"}' -H 'Content-type: application/json'
以上的方式对单个接口测试很方便,但是如果是对多个接口进行压力测试呢?这时就需要用到脚本语言啦,比如Python,那怎么将我们熟悉的curl转为Python脚本呢?

推荐一个网址可以很快速地将curl转为你想要的语言:
https://curlconverter.com/
网站的主页:

如图所示,输入curl command就自动转为Python语言啦!

Get转换如图:

Get请求
curl ' http://baidu.com/userInfo?userId=123&token=iaotjadfaoijtj '
Python

import requests

params = (
('userId', '123'),
('token', 'iaotjadfaoijtj'),

response = requests.get(' http://baidu.com/userInfo ', params=params)

Post转换如图

curl http://baidu.com/userInfo -d '{"userId": 123, "token": "iaotjadfaoijtj"}' -H 'Content-type: application/json'
Python

import requests

headers = {
'Content-type': 'application/json',

data = '{"userId": 123, "token": "iaotjadfaoijtj"}'

response = requests.post(' http://baidu.com/userInfo ', headers=headers, data=data)

综上就实现了转换。