当前位置:网站首页>Detailed explanation of curl command
Detailed explanation of curl command
2022-06-13 03:04:00 【good_ boys】
To quote :https://www.cnblogs.com/fan-gx/p/12321351.html
- CURL send out POST request
curl -H “Content-Type: application/json” -X POST -d ‘{“user_id”: “123”, “coin”:100, “success”:1, “msg”:“OK!” }’ “http://192.168.0.1:8001/test”
Parameters Content
-H Request header
-d POST Content
-X Request protocol
brief introduction
curl Is a common command line tool , Used to request Web The server . Its name is client (client) Of URL Tool means . It's very powerful , There are dozens of command line parameters . If you are skilled , It can completely replace Postman This kind of GUI tool .
-A
-A Parameter specifies the client's user agent header , namely User-Agent.curl The default user agent string for is curl/[version].
$ curl -A ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36’ https://google.com
The above order will User-Agent Change to Chrome browser .
$ curl -A ‘’ https://google.com
The above command will remove User-Agent header .
It can also be done through -H Parameter specifies the header directly , change User-Agent.
$ curl -H ‘User-Agent: php/1.0’ https://google.com
-b
-b Parameter to send... To the server Cookie.
$ curl -b ‘foo=bar’ https://google.com
The above command generates a header Cookie: foo=bar, Send a message to the server called foo、 The value is bar Of Cookie.
$ curl -b ‘foo1=bar;foo2=bar2’ https://google.com
The above command sends two Cookie.
$ curl -b cookies.txt https://www.google.com
The above command reads the local file cookies.txt, It's set by the server Cookie( See -c Parameters ), Send it to the server .
-c
-c Parameter sets the server to Cookie Write a file .
$ curl -c cookies.txt https://www.google.com
The above command will send the HTTP Respond to the set Cookie Write text file cookies.txt.
-d
-d Parameters are used to send POST Requested data body .
$ curl -d’login=emma&password=123’-X POST https://google.com/login
perhaps
$ curl -d ‘login=emma’ -d ‘password=123’ -X POST https://google.com/login
Use -d After the parameters ,HTTP The request will be automatically header Content-Type : application/x-www-form-urlencoded. And will automatically turn the request to POST Method , Therefore, it can be omitted -X POST.
-d Parameter can read the data of the local text file , Send to server .
$ curl -d ‘@data.txt’ https://google.com/login
The command above reads data.txt The content of the document , Send... As data body to the server .
–data-urlencode
–data-urlencode The parameter is equal to -d, send out POST Requested data body , The difference is that the data will be sent automatically URL code .
$ curl --data-urlencode ‘comment=hello world’ https://google.com/login
In the above code , Data sent hello world There is a space between , Need to carry out URL code .
-e
-e Parameter to set HTTP Header for Referer, Indicates the source of the request .
curl -e ‘https://google.com?q=example’ https://www.example.com
The above order will Referer Header set to https://google.com?q=example.
-H Parameters can be added directly by header Referer, Achieve the same effect .
curl -H ‘Referer: https://google.com?q=example’ https://www.example.com
-F
-F Parameters are used to upload binaries to the server .
$ curl -F ‘[email protected]’ https://google.com/profile
The above order will give HTTP Request with header Content-Type: multipart/form-data, Then put the file photo.png As file Field upload .
-F Parameters can be specified MIME type .
$ curl -F ‘[email protected];type=image/png’ https://google.com/profile
The above order specifies MIME The type is image/png, otherwise curl Will be able to MIME The type is set to application/octet-stream.
-F Parameter can also specify the filename .
$ curl -F ‘[email protected];filename=me.png’ https://google.com/profile
In the above command , The original file name is photo.png, But the file name that the server received was me.png.
-G
-G Parameters are used to construct URL The query string for .
$ curl -G -d ‘q=kitties’ -d ‘count=20’ https://google.com/search
The above command will issue a GET request , Actually requested URL by https://google.com/search?q=kitties&count=20. If omitted –G, It will send out a POST request .
If the data requires URL code , Can combine –data–urlencode Parameters .
$ curl -G --data-urlencode ‘comment=hello world’ https://www.example.com
-H
-H Parameter add HTTP Request header .
$ curl -H ‘Accept-Language: en-US’ https://google.com
The above command adds HTTP header Accept-Language: en-US.
$ curl -H ‘Accept-Language: en-US’ -H ‘Secret-Message: xyzzy’ https://google.com
The above command adds two HTTP header .
$ curl -d ‘{“login”: “emma”, “pass”: “123”}’ -H ‘Content-Type: application/json’ https://google.com/login
The above command adds HTTP The request header is Content-Type: application/json, And then use -d Parameter sending JSON data .
-i
-i Parameters print out the response of the server HTTP header .
$ curl -i https://www.example.com
When the above command receives a response from the server , First output the header of the server response , Then leave a blank line , Then output the source code of the web page .
-I
-I Parameter to the server HEAD request , It will return the server HTTP The header is printed .
$ curl -I https://www.example.com
The above command outputs the server pair HEAD A response to a request .
–head The parameter is equal to -I.
$ curl --head https://www.example.com
-k
-k Parameter specifies to skip SSL testing .
$ curl -k https://www.example.com
The above command will not check the server SSL Is the certificate correct .
-L
-L Parameters will make HTTP Request follow server redirection .curl Default does not follow redirection .
$ curl -L -d ‘tweet=hi’ https://api.twitter.com/tweet
–limit-rate
–limit-rate Used to restrict HTTP Bandwidth of requests and responses , Simulate slow network speed environment .
$ curl --limit-rate 200k https://google.com
The above command limits the bandwidth to... Per second 200K byte .
-o
-o Parameter to save the response of the server as a file , Equate to wget command .
$ curl -o example.html https://www.example.com
The above order will www.example.com Save as example.html.
-O
-O Parameter to save the server response as a file , And will URL The last part of is the file name .
$ curl -O https://www.example.com/foo/bar.html
The above command saves the server response as a file , The file named bar.html.
-s
-s Parameters will not output error and progress information .
$ curl -s https://www.example.com
Once the above command is wrong , No error messages will be displayed . If there is no mistake , The operation result will be displayed normally .
If you want to let curl No output , You can use the following command .
$ curl -s -o /dev/null https://google.com
-S
-S Parameter specifies that only error messages are output , Usually with -s Use it together .
$ curl -s -o /dev/null https://google.com
The above command has no output , Unless something goes wrong .
-u
-u Parameter is used to set the user name and password of server authentication .
$ curl -u ‘bob:12345’ https://google.com/login
The above command sets the user name to bob, The password for 12345, Then turn it into HTTP header Authorization: Basic Ym9iOjEyMzQ1.
curl Able to identify URL The user name and password inside .
$ curl https://bob:[email protected]/login
The above command can recognize URL The user name and password inside , Turn it into the HTTP header .
$ curl -u ‘bob’ https://google.com/login
The above command only sets the user name , After execution ,curl The user will be prompted to enter the password .
-v
-v The whole process of parameter output communication , For debugging .
$ curl -v https://www.example.com
–trace Parameters can also be used for debugging , It also outputs raw binary data .
$ curl --trace - https://www.example.com
-x
-x Parameter assignment HTTP The requested agent .
$ curl -x socks5://james:[email protected]:8080 https://www.example.com
The above order specifies HTTP Request by myproxy.com:8080 Of socks5 Sent by agent .
If no agency agreement is specified , The default is HTTP.
$ curl -x james:[email protected]:8080 https://www.example.com
In the above command , The requested agent uses HTTP agreement .
-X
-X Parameter assignment HTTP Requested method .
$ curl -X POST https://www.example.com
The order is right https://www.example.com issue POST request .
边栏推荐
- JVM GC (V)
- Vs 2022 new features_ What's new in visual studio2022
- Applet image component long press to identify supported codes
- Data warehouse notes | 5 factors that need attention for customer dimension modeling
- Graduation project - campus old thing recycling system based on stm32
- Using binary heap to implement priority queue
- PCR validation of basic biological experiments in [life sciences]
- Five old code farmers, program life review: peace of mind is not the place to go
- JVM class loading (I)
- Ijkplayer source code ---setdatasource
猜你喜欢
JVM JMM (VI)
Spark UDF instance details
Introduction to redis (using redis, common commands, persistence methods, and cluster operations)
Operating principle of JS core EventLoop
A wechat app for shopping
JVM class loading (I)
Prometheus安装并注册服务
[data analysis and visualization] key points of data mapping 7- over mapping
二叉樹初始化代碼
When the flutter runs the project, the gradle download fails, and the running gradle task 'assemblydebug' is always displayed
随机推荐
CDN single page reference of indexbar index column in vant framework cannot be displayed normally
Hash table: least recently used cache
[data analysis and visualization] key points of data drawing 5- the problem of error line
Techniques for collecting stringgrid
Ijkplayer source code -- Library loading and initialization
Use and arrangement of wechat applet coordinate position interface (I)
Linked list: palindrome linked list
Vs 2022 new features_ What's new in visual studio2022
Keil去掉烦人的ST-Link更新提示
Beginner development process_ Project development FAQs
Mp4 playback
Android lightweight cache processing
[life science] DNA extraction of basic biological experiments
JS multiple judgment writing
Graduation project - campus old thing recycling system based on stm32
MySQL 8.0 installation free configuration method
Using binary heap to implement priority queue
專業的數據庫管理軟件:Valentina Studio Pro for Mac
wx. Createselectorquery() gets the usage of DOM nodes in components
Vant框架中关于IndexBar索引栏的CDN单页面引用,无法正常展示