当前位置:网站首页>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"边栏推荐
猜你喜欢

Source code analysis of countdownlatch of AQS

prometheus监控nacos

VMware Workstation 配置net模式
![[untitled]](/img/54/660667e528729cc87796d972dc0b17.png)
[untitled]
![[C language] dynamic memory management](/img/bb/2ec65b38e85f53269dc03d885d70f4.png)
[C language] dynamic memory management

Using C language to realize three piece chess games
![[pta ---- traversal of tree]](/img/d8/260317b30d624f8e518f8758706ab9.png)
[pta ---- traversal of tree]

mongoDB复制集及分片集群

C language memcpy library functions and the role of memmove

技术分享 | 接口测试价值与体系
随机推荐
等保3.0-服务器三权分立配置
Analysis of reentrantlock source code of AQS
Pku-2739-sum of constructive prime numbers
QT使用MSVC编译器输出中文乱码问题
Question brushing record - linked list
技术分享 | 使用postman发送请求
[C language] string library function introduction and simulation
[explain in detail how to realize Sanzi chess step by step]
技术分享 | 接口测试价值与体系
QT uses MSVC compiler to output Chinese garbled code
Elastic common high frequency commands
About the collation of shader keyword
Prometheus monitoring Nacos
Rain Scene Effect (I)
HDU-2036-改革春风吹满地(多边形面积模板)
测试面试题集锦(一)| 软件测试常见必考问题与流程篇(附答案)
链表中结点的插入和删除
MySQL常用命令
Yapi vulnerability hanging horse program chongfu.sh processing
Water bottle effect production