The Curl command in Linux is detailed _linux

Source: Internet
Author: User
Tags curl http authentication http post set set

Grammar

# curl [option] [url]

Common parameters:

-a/--user-agent <string>    Set User agent sent to server
-b/--cookie <name=string/file> cookie string or file read location
-c/ Write the     cookie to this file after the--cookie-jar <file> operation
-c/--continue-at <offset>   Breakpoint continues
-d/-- Dump-header <file>    writes header information to the file
-e/--referer         Source URL
-f/--fail failed to           display HTTP error when connection fails
-o/--output         writes the output to the file
-o/--remote-name      writes the output to the file, keeping the file name of the remote file
-r/--range <range>      retrieves the
-s/--silent mute mode from the http/1.1 or FTP server byte range         . Do not output anything
-t/--upload-file <file>     upload files
-u/--user <user[:p assword]>  set up the user and password for the server
-w/--write-out [format]    what output is finished
-x/--proxy  
 

Example:

1. Basic usage

# Curl Http://www.linux.com

Once executed, the www.linux.com HTML will be displayed on the screen.

Ps: Since the installation of Linux many times is not installed desktop, also means that there is no browser, so this method is often used to test whether a server can reach a Web site

2, save access to the Web page

2.1: Using the Linux redirection function to save

# Curl Http://www.linux.com >> linux.html

2.2: You can save the Web page using Curl's built-in option:-o (lowercase)

$ Curl-o linux.html http://www.linux.com

The following interface is displayed when the execution is complete, and 100% indicates that the save was successful

% total% Received% Xferd Average Speed time Time current
        dload Upload Total spent left Speed
100 79684 0 79684 0 0 3437k  0--:--:----:--:----:--:--7781k

2.3: You can use Curl's built-in option:-O (uppercase) to save files in the Web page

Be aware that the URL behind here is specific to a file, or you can't catch it.

# Curl-o Http://www.linux.com/hello.sh

3. Test page return value

# Curl-o/dev/null-s-W%{http_code} www.linux.com

Ps: in the script, this is a very common test site is normal usage

4. Specify proxy server and its port

Many times the internet needs to use a proxy server (such as using a proxy server to surf the Internet or because of the use of curl other people's web site to be shielded by other people's IP address), fortunately curl through the use of built-in option:-x to support the set agent

# curl-x 192.168.100.100:1080 http://www.linux.com

5. Cookies

Some Web sites use cookies to record session information. For browsers such as Chrome, cookie information can be easily processed, but in curl it is easy to handle cookies as long as the relevant parameters are added

5.1: Save the cookie information inside the HTTP response. Built-in option:-c (lowercase)

# curl-c Cookiec.txt http://www.linux.com

After execution, the cookie information is stored in the cookiec.txt.

5.2: The header information inside the HTTP response is saved. Built-in option:-D

# curl-d Cookied.txt http://www.linux.com

After execution, the cookie information is stored in the cookied.txt.

Note: The cookie generated by-C (lowercase) is not the same as the cookie in-D.

5.3: Use cookies

Many sites are monitoring your cookie information to determine whether or not you follow the rules to access their site, so we need to use the saved cookie information. Built-in option:-B

# curl-b Cookiec.txt http://www.linux.com

6, imitate the browser

Some sites need to use specific browsers to access them, and some need to use certain versions. Curl built-in OPTION:-A allows us to specify the browser to access the Web site

# curl-a ' mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0) "Http://www.linux.com

So the server side thinks it's using IE8.0 to access the

7, forged Referer (hotlinking)

Many servers check the Referer of HTTP access to control access. For example: You are first visit the first page, and then visit the first page of the mailbox pages, here to visit the Referer address of the mailbox is to visit the home page after the success of the address, if the server found that the mailbox page to visit the Referer address is not the address of the home, it is a stolen

Curl built-in OPTION:-E allows us to set the Referer

# curl-e "Www.linux.com" http://mail.linux.com

This will give the server the impression that you clicked on a link from www.linux.com.

8, download the file

8.1: Download files using Curl.

#使用内置option:-O (lowercase)

# Curl-o Dodo1.jpg http:www.linux.com/dodo1.jpg

#使用内置option:-O (uppercase)

# Curl-o Yun_qi_img/dodo1. Jpg

This will save the file on the server name to the local

8.2: Cycle Download

Sometimes downloading a picture can be a part of the previous name is the same, on the last caudal name is not the same

# Curl-o Yun_qi_img/dodo[1-5]. Jpg

This will save all the Dodo1,dodo2,dodo3,dodo4,dodo5.

8.3: Under the load name

# Curl-o Yun_qi_img/dodo[1-5]. Jpg

Because the download of Hello and BB in the filename is dodo1,dodo2,dodo3,dodo4,dodo5. So the second download will overwrite the first download, so you need to rename the file.

# Curl-o #1_ #2.jpg yun_qi_img/dodo[1-5]. Jpg

So in Hello/dodo1. JPG files will become hello_dodo1 when downloaded. JPG, other files and so on, thereby effectively avoiding the file being overwritten

8.4: Block Download

Sometimes downloading things will be larger, this time we can segment download. Using built-in Option:-r

# Curl-r 0-100-o Dodo1_part1. JPG Yun_qi_img/dodo1. JPG
# curl-r 100-200-o dodo1_part2. JPG Yun_qi_img/dodo1. JPG
# curl-r 200--o dodo1_part3. JPG Yun_qi_img/dodo1. JPG
# cat dodo1_part* > Dodo1. Jpg

This allows you to view the Dodo1. JPG of the contents of the

8.5: Download files via FTP

Curl can download files via FTP, Curl provides two kinds of syntax for downloading from FTP

# Curl-o-u username: password Ftp://www.linux.com/dodo1.JPG
# Curl-o ftp://username: password @www.linux.com/dodo1.jpg

8.6: Show Download progress bar

# Curl-#-O yun_qi_img/dodo1. Jpg

8.7: Download Progress information will not be displayed

# curl-s-O yun_qi_img/dodo1. Jpg

9, the breakpoint continues to pass

In Windows, we can use the software such as Thunder to carry out a breakpoint extension. Curl can achieve the same effect with built-in option:-c
If you are downloading Dodo1. In the process of JPG suddenly dropped the line, you can use the following way to continue the transmission

# curl-c-O yun_qi_img/dodo1. Jpg

10, Upload files

Curl can not only download files, but also upload files. With built-in option:-t to implement

# curl-t Dodo1. Jpg-u User name: Password ftp://www.linux.com/img/

This will upload the file dodo1 to the FTP server. Jpg

11. Display Crawl Error

# curl-f Http://www.linux.com/error

Other parameters (translated here for reprint):

-a/--append when uploading files, attach to the target file--anyauth can use the "any" authentication method--basic use HTTP Basic authentication-b/--use-ascii using ASCII text Transfer- D/--data <data> HTTP Post mode transfer data--data-ascii <data> post data in ASCII--data-binary <data> in binary mode Post data--negotiate Use HTTP authentication--digest use digital authentication--disable-eprt prohibit the use of eprt or lprt--disable-epsv prohibition of use EPSV- Egd-file <file> Set EGD socket path for random data (SSL)--tcp-nodelay use tcp_nodelay option-e/--cert <cert[:p asswd]> client Certificate File and password (SSL)--cert-type <type> certificate file type (Der/pem/eng) (SSL)--key <key> private key file name (SSL)--key-type &LT;TYPE&G    T Private key file Type (Der/pem/eng) (SSL)--pass <pass> private key password (SSL)--engine <eng> encryption engine uses (SSL). "--engine list" for list--cacert <file> CA certificate (SSL)--capath <directory> CA (made using C_rehash) to Ver Ify peer against (SSL)--ciphers <list> SSL password--compressed requires that the return is a compressed situation (using deflate or gzip)--connect-timeo UT <seconds> set maximum request time--create-diRS Establish directory hierarchy for local directory--crlf upload is to turn LF into CRLF--ftp-create-dirs if the remote directory does not exist, create a remote directory--ftp-method [Multicwd/nocwd/singlec WD] Control the use of CWD--FTP-PASV use PASV/EPSV instead of port--ftp-skip-pasv-ip when using PASV, ignore the IP address--ftp-ssl try to use SSL/TLS for FTP data   Transmission--FTP-SSL-REQD requires SSL/TLS for FTP data transfer-f/--form <name=content> analog HTTP form submission-form-string <name=string>    Simulate HTTP form submission data-g/--globoff disable URL sequences and scopes use {} and []-g/--get send data in Get way-h/--help help-h/--header <line> The length of the custom header information passed to the server--ignore-content-length ignored HTTP header information-i/--include output includes protocol header information-i/--head display only Document information-j/--junk-ses Sion-cookies ignores session cookies when reading files--interface <interface> use specified network interface/address--KRB4 <level> Use specified security level krb4-k/-
-insecure allows you to-k/--config specified profile reads without using certificates to SSL sites-l/--list-only list file names under FTP directory--limit-rate <rate> set transfer speed --local-port<num> enforces the local port number-m/--max-time <seconds> sets the maximum transmission time--max-redirs <num> sets the maximum number of read directories--max-  FileSize <bytes> Set the maximum amount of downloaded files-m/--manual display full manual-N/--NETRC read the username and password from the Netrc file--netrc-optional use. netrc or URLs to overwrite-n--NTLM     Disable buffered output using HTTP NTLM authentication-n/--no-buffer-p/--proxytunnel Use HTTP proxy--proxy-anyauth to select any proxy authentication method--proxy-basic Using Basic authentication on an agent--proxy-digest use digital authentication on the agent--PROXY-NTLM use NTLM authentication on the agent-p/--ftp-port <address> use the port address instead of  Pasv-q/--quote <cmd> file transfer, send a command to the server--range-file read (SSL) random file-r/--remote-time when the file is generated locally, keep the remote file time--retry <num> When a problem occurs, the number of retries--retry-delay <seconds> transmission problems, set retry interval--retry-max-time <seconds> transmission problems, set Set maximum retry time-s/--show-error display error--SOCKS4  

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work to bring certain help, if you have questions you can message exchange.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.