当前位置:网站首页>Technology Sharing | Sending Requests Using cURL
Technology Sharing | Sending Requests Using cURL
2022-08-09 09:59:00 【Tester_muller】
cURL 是一个通过 URL 传输数据的,功能强大的命令行工具.cURL 可以与 Chrome Devtool 工具配合使用,把浏览器发送的真实请求还原出来,附带认证信息,脱离浏览器执行,方便开发者重放请求、修改参数调试,编写脚本.也可以单独使用,根据自己的需求构造请求调整参数,构造多种接口测试场景.
环境安装
学习 curl 命令之前,需要先了解 Chrome Devtool 工具.
ChromeDevTools
Chrome DevTools(Chrome 开发者工具)是内嵌在 Chrome 浏览器里的一组用于网页制作和调试的工具.在测试的过程中,也常常用作一个简单的抓包工具.
如何操作
- 选择右上角 Chrome 菜单,然后选择更多工具 -> 开发者工具
- 或者右键,选择检查/审查元素
在 Network 面板中可以查看通过网络来请求来的资源的详细信息:
cURL常见用法
从浏览器 copy
1、右键左侧数据,选择 Copy -> copy as curl ,即可把请求内容转化为 cURL 命令.
2、将命令 copy 在 gitbash 或 bash 上并运行,则会看到返回信息.
3、对上面命令进行细化,加入 -v 参数可以打印更详细的内容,用2>&1将标准错误重定向到标准输出,发送此命令将得到细化后的内容
细化后的命令如下
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>&1其他常用命令
发起 get 请求
curl "https://httpbin.testing-studio.com/get" -H "accept: application/json"发起 post 请求
curl -X POST "https://httpbin.testing-studio.com/post" -H \
"accept: application/json"proxy 的使用
curl -x 'http://127.0.0.1:8080' "https://httpbin.testing-studio.com/get"curl 命令常用参数
cURL实战演练
通过几个小实战演练,了解一些常用参数的用法
1、篡改请求头信息,将 User-Agent 改为 ”testing-studio
curl -H "User-Agent:testing-studio" "http://www.baidu.com" -v可以看到请求中的 User-Agent 成功改为了 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.在企业微信中通过 curl 命令创建标签,这是一个 post 请求,通过 --data 参数传递 tagname 和 tagid
# token为个人生成,需要替换
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.认证,通过 put 上传到 ElasticSearch ,使用 --user 进行用户认证
# ES_HOST index id content 均为变量,需替换
curl -X PUT "$ES_HOST/$index/_doc/$id?pretty" \
--user username:password \
-H 'Content-Type: application/json' \
-d "$content"边栏推荐
- Quick sort eight sorts (3) 】 【 (dynamic figure deduction Hoare, digging holes, front and rear pointer method)
- [Personal study summary] CRC verification principle and implementation
- Browser error classification
- Tom Morgan | Twenty-One Rules of Life
- 多线程(基础)
- 【size_t是无符号整数 (-1 > 10) -> 1】
- 喜迎排名18
- MySQL关于表的知识点,进来学习!
- 7.FileFilter接口
- .equals==
猜你喜欢

STM32F103实现IAP在线升级应用程序

免费下载天地图全国基础地理信息矢量数据的一种方法

mac 上安装Redis和配置

3D打印了这个杜邦线理线神器,从此桌面再也不乱了
Ontology Development Diary 03 - When debugging is in progress
![[Machine Learning] Basics of Data Science - Basic Practice of Machine Learning (2)](/img/9f/5afabec1b9ab1871130c8bf1bae472.png)
[Machine Learning] Basics of Data Science - Basic Practice of Machine Learning (2)

ArrayList和LinkedList

时间复杂度和空间复杂度

Attentional Feature Fusion

EndNote User Guide
随机推荐
多线程案例——阻塞式队列
超详细的MySQL基本操作
7.FileFilter interface
Tom Morgan | Twenty-One Rules of Life
mac 上安装Redis和配置
LeetCode147:对链表进行插入排序 画图分析 思路清晰!
元组 字典 集合
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
Source GBase database, oracle quote "ORA - 01000: beyond the shop open the cursor"
程序环境和预处理
批量修改Shapefile属性表的一种方法(使用gdal.jar)
LPP code and its comments
日期操作比较全面得代码
Ontology Development Diary 05-Strive to Understand SWRL (Part 2)
循环嵌套以及列表的基本操作
抛出一个问题? Mysql环境下进行Count操作执行的时候速度很慢_需手动给主键添加索引---MySql优化001
Tigase插件编写——注册用户批量查询
2.线程创建
字符串函数和内存函数
【八大排序②】选择排序(选择排序,堆排序)