当前位置:网站首页>Technology sharing | sending requests using curl
Technology sharing | sending requests using curl
2022-07-28 06:51:00 【Yehna rahmin】
cURL It's a pass URL The transmission of data , Powerful command line tools .cURL It can be done with Chrome Devtool Tools used in conjunction with , Restore the real request sent by the browser , With certification information , Execute without browser , Easy for developers to replay requests 、 Modify parameters, debug , Write a script . It can also be used alone , Adjust the parameters according to your own requirements , Construct a variety of interface test scenarios .
Environmental installation
Study curl Before the command , You need to know Chrome Devtool Tools .
ChromeDevTools
Chrome DevTools(Chrome Developer tools ) Is embedded in Chrome A set of tools in the browser for making and debugging web pages . During the test , It is also often used as a simple bag grabbing tool .
How to operate
- Choose the top right corner Chrome menu , Then choose more tools → Developer tools
- Or right click , Select Check / Review element
stay Network In the panel, you can view the details of the resources requested through the network :

cURL Common use
From the browser copy
1、 Right click the data on the left , choice Copy → copy as curl , The request content can be converted into cURL command .
2、 Will command copy stay gitbash or bash And run , You will see the return message .
3、 Refine the above command , Join in -v Parameters can print more details , use 2>&1 Redirect standard error to standard output , Sending this command will get the refined content
The refined command is as follows
curl 'https://home.testing-studio.com/' -H \
'authority: home.testing-studio.com' -H 'pragma: no-cache'\
-H 'cache-control: no-cache' -H 'upgrade-insecure-requests: 1'\
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0)\
AppleWebKit/537.36 (KHTML, like Gecko)\
Chrome/80.0.3987.116 Safari/537.36' \
-H 'sec-fetch-dest: document' \
-H 'accept: text/html,application/xhtml+xml,\
application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,\
application/signed-exchange;v=b3;q=0.9' \
-H 'sec-fetch-site: none' -H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'accept-language: en,zh-CN;q=0.9,zh;q=0.8' \
--compressed -v 2>&1Other common commands
launch get request
curl "https://httpbin.testing-studio.com/get" -H "accept: application/json"launch post request
curl -X POST "https://httpbin.testing-studio.com/post" -H \
"accept: application/json"proxy Use
curl -x 'http://127.0.0.1:8080' "https://httpbin.testing-studio.com/get"curl Common parameters of commands

cURL Practical drill
Through a few small combat drills , Learn the usage of some common parameters
1、 Tamper with request header information , take User-Agent Change it to ”testing-studio
curl -H "User-Agent:testing-studio" "http://www.baidu.com" -vYou can see... In the request User-Agent Success changed to testing-studio
* Trying 14.215.177.39...
* TCP_NODELAY set
* Connected to www.baidu.com (14.215.177.39) port 80 (#0)
> GET / HTTP/1.1
> Host: www.baidu.com
> Accept: */*
> User-Agent:testing-studio2. In the enterprise wechat through curl Command to create a label , This is a post request , adopt --data Parameter passing tagname and tagid
# token Generated for individuals , Need to replace
curl -H "Content-Type: application/json" -X POST \
--data '{"tagname": "hogwarts","tagid": 13}' \
https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=$token3. authentication , adopt put Upload to ElasticSearch , Use --user User authentication
# ES_HOST index id content All variables , To be replaced
curl -X PUT "$ES_HOST/$index/_doc/$id?pretty" \
--user username:password \
-H 'Content-Type: application/json' \
-d "$content"边栏推荐
- JS逆向100题——第1题
- 测试人生 | 二线城市年薪超40W?疫情之下涨薪100% + 是怎么做到的?
- FTP服务
- InitializingBean接口及示例
- C language memcpy library functions and the role of memmove
- Rain Scene Effect (I)
- Redis cache design and performance optimization
- Ubuntu18.04搭建redis集群【学习笔记】
- [pta-- use queues to solve the problem of monkeys choosing kings]
- Fermat's theorem
猜你喜欢

Which is the best and most cost-effective air conduction headset recommended

Which brand of air conduction earphones is better? These four should not be missed

NiO example

思寒漫谈测试人职业发展

How to simulate the implementation of strcpy library functions
![[dynamic planning -- the best period for buying and selling stocks Series 2]](/img/6c/887a026d3c1bcbd278bb7f3e0afd05.png)
[dynamic planning -- the best period for buying and selling stocks Series 2]

技术分享 | 服务端接口自动化测试, Requests 库的这些功能你了解吗?
![[explain in detail how to realize Sanzi chess step by step]](/img/17/68ef51ec2be0c86019461116ecaa82.png)
[explain in detail how to realize Sanzi chess step by step]
![[c language] - step by step to achieve minesweeping games](/img/ee/49ddfcd948ccd5c8c9dec3c48c6112.png)
[c language] - step by step to achieve minesweeping games

JS reverse question 100 - question 1
随机推荐
技术分享 | 接口测试常用代理工具
[pta-- use queues to solve the problem of monkeys choosing kings]
MySQL master-slave
SSAO by computer shader (II)
技术分享 | 使用 cURL 发送请求
PKU-2524-Ubiquitous Religions(并查集模板)
Skimming records -- sequence traversal of binary tree
HDU-5783 Divide the Sequence(贪心水题)
About the collation of shader keyword
Using C language to realize three piece chess games
Build php7 private warehouse
Leetcode brush question diary sword finger offer II 055. binary search tree iterator
[queue, simple application of stack ---- packaging machine]
如何描述一个BUG以及BUG级别的定义、生命周期
JS逆向100题——第1题
项目编译NoSuch***Error问题
Gerapy use
技术分享 | 使用postman发送请求
Initializingbean interface and examples
PKU-2739-Sum of Consecutive Prime Numbers(筛素数法打表)