One, GET request
Curl "http://www.baidu.com" if the URL here points to a file or a picture can be downloaded directly to the local
Curl-i "http://www.baidu.com" Show All information
Curl-l "http://www.baidu.com" only displays header information
Curl-v "Http://www.baidu.com" shows the full process of GET request parsing
wget "http://www.baidu.com" can also be
Second, POST request
Curl-d "Param1=value1¶m2=value2" "http://www.baidu.com"
Third, the JSON format of the POST request
Curl-l-H "Content-type:application/json"-X post-d ' {"Phone": "13521389587", "Password": "Test"} ' http://domain/apis/ Users.json
For example:
Curl-l-H "Content-type:application/json"-X post-d ' {"ver": "1.0", "SOA": {"req": "123"}, "Iface": " Me.ele.lpdinfra.prediction.service.PredictionService "," Method ":" Restaurant_make_order_time "," args ": {" arg2 ":" \ " Stable\ "", "arg1": "{\" code\ ": [\" wind\ "],\" temperature\ ": 11.11}", "arg0": "{\" tracking_id\ ": \" 100000000331770936\ " , \ "eleme_order_id\": \ "100000000331770936\", \ "platform_id\": \ "4\", \ "restaurant_id\": \ "482571\", \ "dish_num\": 1,\ "Dish_info\": [{\ "entity_id\": 142547763,\ "quantity\": 1,\ "category_id\": 1,\ "dish_name\": \ "[0xe7][0x89][0xb9][ 0xe4][0xbb][0xb7][0xe8][0x85][0x8a][0xe5][0x91][0xb3][0xe5][0x8f][0x89][0xe7][0x83][0xa7][0xe5][0x8f][0x8c][ 0xe6][0x8b][0xbc][0xe7][0x85][0xb2][0xe4][0xbb][0x94][0xe9][0xa5][0xad]\ ", \" price\ ": 31.0}],\" merchant_location \ ": {\" longitude\ ": \" 121.47831425\ ", \" latitude\ ": \" 31.27576153\ "},\" customer_location\ ": {\" longitude\ ": \" 121.47831425\ ", \" latitude\ ": \" 31.27576153\ "},\" created_at\ ": 1477896550,\" confirmed_at\ ": 1477896550,\" Dishes_ Total_price\ ": 0.0,\" Food_boxes_totAl_price\ ": 2.0,\" delivery_total_price\ ": 2.0,\" pay_amount\ ": 35.0,\" city_id\ ": \" 1\ "}"}} '/HTTP/ Vpcb-lpdinfra-stream-1.vm.elenet.me:8989/rpc
Ps:json string inner layer parameters need to be formatted
Description of Use
The Curl command is a powerful network tool that can download files via HTTP, FTP, and so on, and can also upload files. In fact, curl is far more than the previous features, and you can get more information from the man Curl reading the manual page. Similar tools also have wget.
The Curl command uses the Libcurl library to implement, Libcurl library commonly used in the C program to handle HTTP requests, CURLPP is a C + + package Libcurl, these things can be used in crawling Web pages, network monitoring and other aspects of development, The Curl command can help resolve problems that are encountered during development.
Common Parameters
There are many parameters to the Curl command, and here are just a list of those I used, especially in shell scripts.
-A: Feel free to specify your own browser information as claimed by this visit
-b/--cookie <name=string/file> Cookie string or file read location, use option to append the last cookie information to the HTTP request.
-c/--cookie-jar <file> Write cookies to this file after the operation is complete
-c/--continue-at <offset> Breakpoint Continuation
-d/--data <data> HTTP Post mode transfer data
-d/--dump-header <file> Write header information to this file
-f/--form <name=content> analog HTTP form submission data
The-v/--verbose lowercase v parameter, which is especially useful in debugging scripts, is used to print more information, including sent request information.
-m/--max-time <seconds> Specifies the maximum length of time to process
-h/--header
-s/--slient reduce the output of information, such as progress
--connect-timeout <seconds> Specifies the maximum length of time to attempt a connection
-x/--proxy <proxyhost[:p ort]> Specify proxy server address and port, port defaults to 1080
-t/--upload-file <file> Specify upload file path
-o/--output <file> Specify output file name
--retry <num> Specify the number of retries
-e/--referer <URL> Specify a reference address
-i/--head only returns header information, using head request
-u/--user <user[:p assword]> setting up the user and password for the server
-O: According to the file name on the server, automatically exists local
-r/--range <range> retrieving byte ranges from http/1.1 or FTP servers
-t/--upload-file <file> Uploading files
using the example
1, crawl the page content into a file
[email protected] mytest]# Curl-o home.html http://www.baidu.com --The Baidu home page content to grasp down to the home.html
[[email protected] mytest] #curl-o #2_ #1.jpg http://cgi2.tky.3web.ne.jp/~{a,b}/[001-201]. JPG
Because the file name under A/b is 001,002...,201, downloaded files with the same name, so that the custom download down the filename, it becomes this: the original: a/001.jpg--> after download: 001-a.jpg Original: B/001.jpg--- > After download: 001-b.jpg
2, with-O (uppercase), the following URL to specific to a file, or not catch it down. You can also use regular to grab things.
[email protected] mytest]# Curl-o http://img.voidcn.com/vcimg/000/000/767/511_420_fe4.gif
The results of the operation are as follows:
% total % Received% xferd Average speed& nbsp; time time time current
dload upload total spent left speed
100 1575 100 1575 0 0 14940 0--:--:----:--:----:--:--1538k< /span>
A bdlogo.gif picture is generated in the current execution directory.
[email protected] mytest]# Curl-o http://xxxxx/screen[1-10]. JPG --Download screen1.jpg~screen10.jpg
3, simulate form information, simulate login, save cookie Information
[email protected] mytest]# curl-c/cookie_c.txt-f log=aaaa-f pwd=****** http://www.XXXX.com/wp-login.php
4, simulating form information, simulating login, saving header information
[email protected] mytest]# curl-d/cookie_d.txt-f log=aaaa-f pwd=****** http://www.XXXX.com/wp-login.php
The cookie generated by-C (lowercase) is not the same as the cookie in-D.
5, use cookie file
[email protected] mytest]# curl-b./cookie_c.txt Http://www.XXXX.com/wp-admin
6, the breakpoint continues to pass,-C (uppercase)
[email protected] mytest]# curl-c-o http://img.voidcn.com/vcimg/000/000/767/511_420_fe4.gif
7, transfer the data, it is best to use the login page test , because you pass the value of the past, curl back to grasp the data, you can see that you pass the value has no success
[email protected] mytest]# curl-d log=aaaa http://www.XXXX.com/wp-login.php
8, show the fetch error, the following example, it is very clear that.
[Email protected] mytest]# curl-fhttp://www.XXXX.com/asdf
Curl: () The requested URL returned error:404
[[email protected] mytest]# Curl HTTP://WWW.XXXX.COM/ASDF
9, forged source address, some website will judge, request source address, prevent hotlinking.
[Email protected] mytest]# curl-ehttp://localhosthttp://www.XXXX.com/wp-login.php
10, when we often use curl to engage in people's things, people will put your IP to shield off, this time, we can use the agent
[email protected] mytest]# curl-x 24.10.28.84:32779-o home.html http://www.XXXX.com
11, than the larger stuff that we can download in sections
[email protected] mytest]# curl-r 0-100-o img.part1http://www. xxxx.com/wp-content/uploads/2010/09/compare_varnish.jpg
% total% Received% xferd Average speed Time Time current
Dload Upload Total spent
101 101 0 0 0--:--:----:---:----:--:--0
[email protected] mytest]# curl-r 100-200-o img.part2http://www. xxxx.com/wp-ontent/uploads/2010/09/compare_varnish.jpg
% total% Received% xferd Average speed Time Time current
Dload Upload Total spent
100 101 100 101 0 0 57 0 0:00:01 0:00:01--:--:--0
[email protected] mytest]# curl-r 200--o img.part3http://www. xxxx.com/wp-content/uploads/2010/09/compare_varnish.jpg
% total% Received% xferd Average speed Time Time current
Dload Upload Total spent
104k 104k 0 0 52793 0 0:00:02 0:00:02--:--:--88961
[[email protected] mytest]# ls |grep part | Xargs Du-sh
4.0K One.part1
112K Three.part3
4.0K Two.part2
When you use them, cat Ok,cat img.part* >img.jpg
12, download progress information is not displayed
[email protected] mytest]# curl-s-o aaa.jpg http://img.voidcn.com/vcimg/000/000/767/511_420_fe4.gif
Display the download progress bar
[email protected] mytest]# curl-0 http://img.voidcn.com/vcimg/000/000/767/511_420_fe4.gif ( in HTTP 1.0 protocol Requests )
####################################################################### 100%
Download the file via FTP
[[email protected] ~]$ curl-u username: password-ohttp://www.XXXX.com/demo/curtain/bbstudy_files/style.css
% total% Received% xferd Average speed Time Time current
Dload Upload Total spent
101 1934 101 1934 0 0 3184 0--:--:----:--:----:--:--7136
[[email protected] ~]$ curl-u Username: password-o Http://www.XXXX.com/demo/curtain/bbstudy_files/style.css
% total% Received% xferd Average speed Time Time current
Dload Upload Total spent
101 1934 101 1934 0 0 3184 0--:--:----:--:----:--:--7136
Or in the following way
[[email protected] ~]$ Curl-o ftp://user name: Password @ip:port/demo/curtain/bbstudy_files/style.css
[[email protected] ~]$ Curl-o ftp://user name: Password @ip:port/demo/curtain/bbstudy_files/style.css
15, upload via FTP
[[email protected] ~]$ curl-t test.sql ftp://user name: Password @ip:port/demo/curtain/bbstudy_files/
[[email protected] ~]$ curl-t test.sql ftp://user name: Password @ip:port/demo/curtain/bbstudy_files/
15, Analog Browser header
[email protected] ~]$ curl-a "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) "-X 123.45.67.89:1080-o page.html-d cookie0001.txthttp://www.www.baidu.com
16,put, GET, POST
such as curl-t localfile http://cgi2.tky.3web.ne.jp/~zz/abc.cgi , The protocol used is the put method of HTTP;
just said put, and naturally remembered several other methos-- get and post.
http submits a form that is more commonly used for post mode and get mode
Get mode what option is not needed, just write the variable in the URL.
Like what:
Curl http://www.yahoo.com/login.cgi?user=nick&password=12345
The option for Post mode is-D
For example, curl-d "user=nick&password=12345" http://www.yahoo.com/login.cgi
is equivalent to issuing a login request to this site ~~~~~
In the end to use the Get mode or post mode, the opposite server to see the program settings.
It is important to note that file uploads on files in post mode, such as
<form method= "POST" enctype= "Multipar/form-data" action= "http://cgi2.tky.3web.ne.jp/~zz/up_file.cgi" >
<input Type=file name=upload>
<input type=submit name=nick value= "Go" >
</form>
Such an HTTP form, which we want to emulate with curl, is the syntax:
curl-f [email protected]-F Nick=go http://cgi2.tky.3web.ne.jp/~zz/up_file.cgi
Every day a Linux command 13 curl sends an HTTP request