当前位置:网站首页>Common usage of curl command
Common usage of curl command
2022-07-27 12:21:00 【LOOPY_ Y】
CURL Commands are commonly used
This article refers to the following articles , The content of this article is limited , For more information, please see the reference articles listed below :
https://www.coonote.com/linux/linux-cmd-curl.html
https://www.ruanyifeng.com/blog/2011/09/curl.html
https://www.ruanyifeng.com/blog/2019/09/curl-reference.html
1 Grammar and common options
1.1 grammar
curl ( Options ) ( Parameters )
1.2 Options
Here are just a few options that I think are commonly used , Want to know more , You can see https://www.coonote.com/linux/linux-cmd-curl.html.
| Options | explain |
|---|---|
| -H / --header | Custom header information |
| -b / --cookie <name=string/file> | cookie String or file read location |
| -d / --data | HTTP POST Way to transmit data |
| -X / --request | What order to give |
| -i / --include | The output contains the header information of the response |
| -I / --head | Only the header information of the response is output |
| -v | The whole process of output communication , For debugging |
▉-H Used to add HTTP Request header information
Add a single request header :
curl -H "Content-Type: application/json" http://www.test.com
perhaps
curl --header "Content-Type: application/json" http://www.test.com
Add multiple request headers :
curl -H "Content-Type: application/json" —H "Accept-Language: zh-CN" http://www.test.com
Equate to
curl -H "Content-Type: application/json; Accept-Language: en-US" http://www.test.com
▉-b Used to send... To the server Cookie data
curl -b "name=value" http://www.test.com
Or from cookiesFile Get to the cookie Information
curl -b cookiesFile http://www.test.com
▉-d Used for sending POST Request body in request Body data
for example :
curl -H 'Content-Type: application/json' -X POST -d '{"name": "july","password": "123456"}' http://www.test.com
Put the request body data into the file , To configure -d @filename, Then you can go from filename Get the request body data in the file , as follows :
curl -H 'Content-Type: application/json' -X POST -d @data.txt http://www.test.com
another , Attention should be paid to , If the request body data adopts json Format , Be sure to configure the request header Content-Type by application/json, Because use -d After the parameter ,HTTP The request will automatically add a request header Content-Type by application/x-www-form-urlencoded, Turn request to POST Method ( Therefore, it can be omitted -X POST).
▉-X Is used to specify the HTTP Request method of (GET、POST etc. )
send out POST request :
curl -X POST http://www.test.com
send out GET request :
curl -X GET http://www.test.com
send out DELETE request :
curl -X DELETE http://www.test.com
▉-i The output contains the header information of the response
After the command receives the server response , First output the header of the server response , Then leave a blank line , Then output the source code of the web page or return information .
D:\>curl -i https://www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 2443
Content-Type: text/html
Date: Mon, 30 May 2022 12:33:22 GMT
Etag: "588603e2-98b"
Last-Modified: Mon, 23 Jan 2017 13:23:46 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.min.css><title> use Baidu Search , You will know </title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus=autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value= use Baidu Search class="bg s_btn" autofocus></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav> Journalism </a> <a href=https://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav> Map </a> <a href=http://v.baidu.com name=tj_trvideo class=mnav> video </a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav> tieba </a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb> Sign in </a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb"> Sign in </a>');
</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;"> More products </a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com> About Baidu </a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/> Read Before Using Baidu </a> <a href=http://jianyi.baidu.com/ class=cp-feedback> Feedback </a> Beijing ICP Prove 030173 Number <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
D:\>
▉-I Only the header information of the response is output
After the command receives the server response , Only the header of the server response is output , No longer output the source code of the web page or return information .
D:\>curl -I https://www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 277
Content-Type: text/html
Date: Mon, 30 May 2022 12:33:32 GMT
Etag: "575e1f59-115"
Last-Modified: Mon, 13 Jun 2016 02:50:01 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
D:\>
▉-v The whole process of output communication , For debugging
As follows GET Request calling http://localhost:8082/word?keyWord=water Print content of :
D:\>curl -v http://localhost:8082/word?keyWord=water
* Trying 127.0.0.1:8082...
* Connected to localhost (127.0.0.1) port 8082 (#0)
> GET /word?keyWord=water HTTP/1.1
> Host: localhost:8082
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Mon, 30 May 2022 12:15:24 GMT
<
{
"code":200,"msg":" Successful operation ","success":true,"data":[],"time":"2022-05-30 20:15:24"}
* Connection #0 to host localhost left intact
D:\>
2 HTTP Interface call example
2.1 GET request
Call without parameters :
curl --request GET http://www.test.com
Equate to :
curl -X GET http://www.test.com
Call with parameters :
curl --request GET http://www.test.com?name=test&password=12345
because curl The default is HTTP GET request , That is, it can also be directly omitted -X GET( or --request GET):
curl https://www.baidu.com
2.2 POST request
curl -H 'Content-Type: application/json' -X POST -d '{"name": "july","password": "123456"}' http://www.test.com
Request body data from file data.txt Read from :
curl -H 'Content-Type: application/json' -X POST -d @data.txt http://www.test.com
Or omit -X POST:
curl -H 'Content-Type: application/json' -d @data.txt http://www.test.com
3 WebService Interface call example
webservice It's actually post Request plus xml data , So use curl post Request simulation webservice. as follows ,data.xml Is requested xml data .
curl -H "Content-Type: text/xml;charset=UTF-8" -H "SOAPAction: ''" -X POST -d @data.xml http://ip:port/xxxxxService?wsdl
It's best to complete SOAPAction Value :
curl -H 'Content-Type: text/xml;charset=UTF-8' -H 'SOAPAction: "testxxx"' -X POST -d @data.xml http://ip:port/xxxxxService?wsdl
边栏推荐
- Detailed explanation of flask framework
- Do you really understand the underlying data structure skip list of Zset in redis?
- Example of MATLAB dichotomy (example of finding zero point by dichotomy)
- 2021-3-19-byte-face value
- Sword finger offer notes: T53 - I. find numbers in the sorted array
- Wechat applet must use interface "suggestions collection"
- go入门篇 (2)
- 我在英国TikTok做直播电商
- shell中的while循环实例
- Mysql8msi installation tutorial (database mysql installation tutorial)
猜你喜欢
One article to understand the index of like in MySQL

Shutter project scrollcontroller attached to multiple scroll views, failed assertion: line 109 POS 12 error handling

SMA TE: Semi-Supervised Spatio-Temporal RepresentationLearning on Multivariate Time Series

NPM step pit

Fundamentals of mathematics 01

Could not load dynamic library ‘libcudnn.so.8‘;
Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!

About the problem that the onapplicationevent method of the custom listener is executed multiple times
![[untitled] multimodal model clip](/img/f0/8ae72ae0845372b6fe2866fae83f52.png)
[untitled] multimodal model clip

最强分布式锁工具:Redisson
随机推荐
One article to understand the index of like in MySQL
go入门篇 (3)
最强分布式锁工具:Redisson
评价自动化测试优劣的隐性指标
5V boost 9V chip
53 亿 BI 市场 TOP 10:帆软、微软、永洪、SAP、百度、IBM、SAS、思迈特、Salesforce、浪潮通软
严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理
快抖抢救“失意人”
CLS 监控告警:实时保障线上服务高可用性
广东:剧本杀等新行业新业态场所,消防安全监管不再“缺位”
20210408 longest public prefix
我在英国TikTok做直播电商
2021-3-19-byte-face value
硬刚甲方后:中国移动 4908 万大单被废
孤独的年轻人,戒不了Jellycat
The chess robot "broke" the chess boy's finger...
The first case of monkeypox in pregnant women in the United States: the newborn was injected with immunoglobulin and was safely born
V-show failure
Guangdong's finance has taken many measures to help stabilize the "ballast stone" of food security
Advance in the flutter project_ image_ Picker component usage