当前位置:网站首页>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
边栏推荐
- Kazoo tutorial
- Ali II: what if the AOF file in redis is too large?
- Shake quickly to rescue the "frustrated person"
- B 站 713 事故后的多活容灾建设|TakinTalks 大咖分享
- go入门篇 (3)
- 20210422 consolidation interval
- mysql8msi安装教程(数据库mysql安装教程)
- 开关量输入输出模块DAM-5055
- Leetcode 02: sword finger offer 58 - I. flip the word order (simple); T123. Verify palindrome string; T9. Palindromes
- Write and read system temporary files: createtempfile and tempfilecontent[easy to understand]
猜你喜欢

I do live e-commerce in tiktok, UK

孤独的年轻人,戒不了Jellycat

JS-寄生组合式继承
![[untitled] multimodal model clip](/img/f0/8ae72ae0845372b6fe2866fae83f52.png)
[untitled] multimodal model clip

Chapter 7 exception handling

Could not load dynamic library ‘libcudnn.so.8‘;
Do you really understand the underlying data structure skip list of Zset in redis?

Bishi journey

About the problem that the onapplicationevent method of the custom listener is executed multiple times

5V boost 9V chip
随机推荐
Ali II: what if the AOF file in redis is too large?
I do live e-commerce in tiktok, UK
Shell script text three swordsman awk
shell中的while循环实例
Advance in the flutter project_ image_ Picker component usage
Weibo comment crawler + visualization
严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理
53 亿 BI 市场 TOP 10:帆软、微软、永洪、SAP、百度、IBM、SAS、思迈特、Salesforce、浪潮通软
Write and read system temporary files: createtempfile and tempfilecontent[easy to understand]
Check the number of file descriptors opened by each process under the system
Idea: can't use subversion command line client: SVN solution
STS下载教程(include官网无法下载解决方案)
微信小程序必用接口「建议收藏」
快抖抢救“失意人”
2021-3-17-byte-hu Pai
Detailed explanation of deeplab series (simple and practical annual summary)
JS字符串方法总结
虚拟偶像的歌声原来是这样生成的!
I/O实例操作
Shutter project scrollcontroller attached to multiple scroll views, failed assertion: line 109 POS 12 error handling