Curl command details

Source: Internet
Author: User
Tags how to use curl http authentication rfc

Curl is an open source file transmission tool that uses the URL syntax in the command line mode. It is widely used in UNIX and multiple Linux distributions, and has dos, Win32, and win64 versions.

Concept editing supports many protocols: FTP, ftps, HTTP, https, Gopher, telnet, dict, file, and LDAP. Curl also supports HTTPS authentication, http post, http put, FTP upload, Kerberos authentication, HTTP upload, proxy server, cookies, user name/password authentication, and resumable download of downloaded files, resumable upload of uploaded files, the HTTP Proxy Server pipeline (proxy tunneling), and even IPv6 and SOCKS5 proxy servers, which upload files to the FTP server through the HTTP proxy server, are very powerful. Network ant in the Windows operating system, which can be achieved by the flash get function. To be accurate, curl supports file upload and download. Therefore, curl is a comprehensive transmission tool. However, users often call curl a download tool. Curl is developed by the Swedish curl organization and you can access: http://curl.haxx. se/to get its source code and related instructions. Since curl is widely used in Linux, IBM includes this software in the AIX Linux toolbox CD, and you can visit the IBM website: http: // www-1. IBM. download COM/servers/AIX/products/aixos/Linux/altlic.html. Currently, curl to the latest version is 7.37.0, which was released in May 21, 2014. The official download site provides three methods: source code tar compressed package, RPM package, and EXE file, and provides the installation method under Ubuntu. [1] In http://curl.haxx. se/docs/, you can download the man help in UNIX format, which has detailed instructions for using the curl tool. Curl: curl [Options] [url...] among them, options is the parameters required for download, and there are more than 80 parameters. Each function of curl relies entirely on these parameters. For more information about the parameters, see the curl man help. Next, this article describes how to use curl for download based on specific examples. [2] 2 Design Method edit get page use command: curl http://curl.haxx. Se this is the easiest way to use. Use this command to get the page that the http://curl.haxx. Se points to, similarly, if the URL points to a file or a picture, it can be downloaded directly to the local. If the HTML document is downloaded, the file header is not displayed by default, that is, the header of the HTML document. To display all, add the parameter-I. to display only the header, use the parameter-I. At any time, you can use the-V command to see how curl works. All commands sent to the server are displayed. For resumable data transfer, you can use the-R parameter to specify the transmission range. Form is an important element in web page design. Form is usually used to collect and submit information to the website. There are two methods to submit information: Get method and post method. First, we will discuss the get method. For example, the page contains the following section: <form method = "get" Action = "junk. cgi "> <input type = text name =" birthyear "> <input type = submit name = Press value =" OK "> </form> a text box and button marked as "OK. Press this button to submit the text box data to the server using the get method. For example, the original page is in www. hotmail. COM/when/birth.html, enter 1905 in the text box, and then press OK. Then, the URL of the browser should be: "www. hotmail. COM/when/junk. CGI? Birthyear = 1905 & press = OK "for such web pages, curl can be processed directly. For example, to obtain the above Web page, you only need to enter: curl" www. hotmail. COM/when/junk. CGI? Birthyear = 1905 & press = OK. The second method used to submit information for a form is the POST method. The difference between the POST method and the get method is that when the get method is used, the browser will generate the target URL, but the POST method will not. Similar to get, there is a webpage: <form method = "Post" Action = "junk. cgi "> <input type = text name =" birthyear "> <input type = submit name = Press value =" OK "> </form> a text box and the button marked as "OK. Press this button and use the POST method to submit data to the server. At this time, the URL is invisible, so you need to use a special method to capture this page: curl-d "birthyear = 1905 & press = OK" www. hotmail. COM/when/junk. cgi Command. At the end of 1995, RFC 1867 defined a new post method to upload files. It is mainly used to upload local files to the server. The page is written as follows: <form method = "Post" enctype = 'multipart/form-data' action = "upload. cgi "> <input type = file name = upload> <input type = submit name = Press value =" OK "> </form> for such pages, the curl usage is different: curl-f [email protected]-F press = OK URL this command uploads local files to the server using post. There are still many usage related to post. You can explore it yourself. The standard method for uploading files using the puthttp protocol is put. In this case, the curl command uses the-t parameter curl-T uploadfile www. uploadhttp. COM/receive. CGI-related authentication curl can handle authentication pages in various situations, such as downloading the user name/Password Authentication Mode page (in IE, an input box for entering the user name and password is usually displayed ): curl-u name: Password www. secrets. com if the network is through the HTTP Proxy Server, and the proxy server requires the user name and password, then enter: curl-u proxyuser: proxypassword http://curl.haxx. when you need to enter the user name and password, you can only specify the user name in the parameter and leave the password blank. Curl allows the user to enter the password interactively. Reference when some network resources are accessed, they must jump through another network address. This is called Referer, reference. For resources with this address, curl can also be downloaded: curl-e http://curl.haxx. se Daniel. haxx. se indicates that some network resources on the user end must first determine which browser the user is using to download or browse only when it meets the standards. In this case, curl can disguise itself as any other Browser: curl-a "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" url. This command indicates that curl is disguised as ie5.0, the user platform is Windows 2000. (The opposite server determines the client type based on this string, so it doesn't matter even if AIX is used ). Use: curl-a "Mozilla/4.73 [En] (X11; U; Linux 2.2.15 i686)" URL to change curl to Netscape and run on Linux on piII. Cookiescookie is a frequently used method for servers to remember customer information. If the cookie is recorded in a file, run the following command: curl-B stored_cookies_in_file www. cookiesite. comcurl can write a new Cookie based on the old cookie and send it to the Website: curl-B cookies.txt-C newcookies.txt www. cookiesite. com encryption HTTP if the web page is transmitted through the HTTPS protocol encrypted by OpenSSL, curl can be accessed directly: curl https://that.secure.server. for comhttp authentication, if the HTTP address of the certificate is used and the certificate is local, curl uses: curl-e mycert. PEM https://that.secure.server. com considerations curl is very broad. To use this tool well, in addition to learning parameters in detail, you also need to have a deep understanding of the various HTTP protocols and URL syntaxes. Here we recommend several reading books: RFC 2616 HTTP syntax definition. RFC 2396 defines the URL syntax. How does RFC 2109 cookie work. RFC 1867: How to post HTTP and the format of post. Linux curl command-A/-- append when uploading files, attach to the target file-A/-- User-Agent <string> to set the user proxy to be sent to the server-anyauth. You can use the "any" authentication method-B/-- cookie <name = string/ file> cookie string or file reading location-Basic use HTTP basic verification-B/-- use-ASCII use ASCII/text transmission-C/-- cookie-jar <File> the cookie is written to this file.-C/-- continue-at <OFFSET> resumable transfer-D/-- Data <DATA> transmits data in http post mode -- Data-ASCII <DATA> post Data in ASCII mode -- Data-binary <DATA> post data in binary mode -- negotiate uses HTTP Authentication -- digest uses digits Verification -- disable-eprt disable the use of eprt or lprt -- disable-epsv disable the use of EPSV-D/-- dump-header <File> write header information to the file -- EGD-file <File> for random data (SSL) set EGD socket path -- TCP-nodelay use tcp_nodelay option-E/-- Referer source URL-E/-- Cert <Cert [: passwd]> 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 <type> private key file type (der/PEM/eng) (SSL) -- pass <pass> private key password (SSL) -- engine <Eng> encryption engine usage (SSL ). "-- engine L Ist "For list -- cacert <File> Ca certificate (SSL) -- capath <directory> Ca directory (made using c_rehash) to verify peer against (SSL) -- ciphers <list> SSL password -- compressed requires that the returned results be compressed (using deflate or gzip) -- connect-Timeout <seconds> sets the maximum request time -- create-dirs creates the directory hierarchy of the local directory -- CRLF upload is to convert lf into CRLF-F/-- not displayed when fail connection fails HTTP Error -- FTP-create-dirs if the remote directory does not exist, create a remote directory -- FTP-method [multicwd/nocwd/singlecwd] to control the use of CWD -- FTP-PASV uses PASV/epsv to replace the end Port -- when the ftp-Skip-PASV-IP uses PASV, ignore this IP address -- FTP-SSL tries to use SSL/TLS for FTP data transmission -- FTP-SSL-reqd requires the use of SSL/TLS for FTP data transmission-F/-- form <name = content> simulate HTTP Form submission data-form-string <name = string> simulate HTTP Form submission data-g/-- globoff disable URL sequence and range use {} and []-G /-- get sends data in get mode-H/-- Help-H/-- header <line> Custom header information to the HTTP header ignored by the server -- ignore-Content-Length header information length-I/-- include when output contains protocol header information-I/-- head only displays Document Information read from the file-J/-- junk-session-Cookies ignore session cookies- Interface <interface> specify Network Interface/address use-krb4 <level> enable the krb4-j with the specified security level/-- junk-session-cookies to read files into ignore session cookies -- interface <interface> use the specified network interface/address -- krb4 <level> to use the krb4-k/-- insecure for the specified security level to allow access to the configuration file specified by-k/-- config without using the certificate to the SSL site/ -- list-only lists the file names under the FTP directory -- limit-rate <rate> sets the transmission speed -- local-port <num> forces the use of the local port number-M/-- Max-time <seconds> set the maximum transmission time -- Max-redirs <num> set the maximum number of read directories -- Max-filesize <bytes> set the maximum number of downloaded files-M/-- manual display all manually -N/-- use NETRC-optional to read the user name and password from the netrc file. netrc or URL to overwrite-n -- NTLM use http ntlm Identity Authentication-N/-- no-buffer disable buffer output-O/-- output write output to this file-O/-- remote -Name: writes the output to the file, retain the remote file name-P/-- Proxytunnel use HTTP Proxy -- proxy-anyauth select any proxy authentication method -- proxy-Basic use basic authentication on the proxy -- proxy-Digest on the proxy use digital authentication -- proxy-NTLM on the proxy use NTLM authentication-P/-- FTP-port <address> use the port address, instead of sending the command to the server-r/-- range <range> retrieve from HTTP/1 before using PASV-Q/-- quote <cmd> File Transfer. 1 or the FTP server's byte range -- range-File Reading (SSL) random file-r/-- remote-time when a file is generated locally, retention time of remote files -- retry <num> Number of retries -- retry-delay <seconds>, set the Retry Interval -- retry-max-time <seconds> when transmission fails, set the maximum retry time-S/-- silent mute mode. Do not output anything-S/-- show-error Display Error -- socks4 Curl command details

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.