Curl is a File Transfer tool that uses the URL syntax to work in the command line mode. It 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 curl in Sweden. You can access the source code and related instructions of the obtained region at http://curl.haxx.se. Because 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.com/servers/aix/products/aixos/linux/altlic.htmlto download fuse. The latest curl version is 7.10.8 and 7.9.3 is provided on the IBM website. The installation on AIX is very simple. The RPM package is downloaded on the IBM website.
In. 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.
1. Get a page
Use the command: curl http://curl.haxx.se
This is the simplest way to use it. 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, you can download it directly to your local machine. 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.
2. Get form
In web page design, form is an important element. 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 a button marked as "OK" appear in the browser. Press this button to submit the text box data to the server using the get method. For example, the original page is:
"Www.hotmail.com/when/junk.cgi? Birthyear = 1905 & press = OK"
For such a webpage, curl can be processed directly. For example, to obtain the webpage above, you only need to enter:
Curl "www.hotmail.com/when/junk.cgi? Irthyear = 1905 & press = OK"
You can.
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 a button marked as "OK" appear in the browser. Press this button and use the POST method to submit data to the server. In this case, 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
This command can be used.
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 upload = @ localfilename-F press = OK [url]
The essence of this command is to upload local files to the server using post. There are still many usage related to post. You can explore it yourself.
3. Use the put method.
The standard method for uploading HTTP files is put. In this case, the curl command uses the-t parameter:
Curl-T uploadfile www.uploadhttp.com/receive.cgi
4. Authentication.
Curl can handle authentication pages in various situations, such as downloading the user name/Password Authentication Mode (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 sent out through the HTTP Proxy Server, and the proxy server requires the user name and password, enter:
Http://curl.haxx.se curl-u proxyuser: proxypassword
When you need to enter the user name and password, specify the user name in the parameter and leave the password blank. Curl allows the user to enter the password interactively.
5. reference.
When some network resources are accessed, they must jump through another network address. This is called Referer, reference. For resources with such addresses, curl can also be downloaded:
Curl-e http://curl.haxx.se Daniel. haxx. se
6. Specify the user client.
Some network resources first need to determine which browser the user is using and can be downloaded or browsed only when they meet 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, and 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 ). Usage:
Curl-a "Mozilla/4.73 [En] (X11; U; Linux 2.2.15 i686)" [url]
Now curl becomes Netscape and runs on Linux of piII platform.
7. Cookies
Cookies are frequently used by 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.com
Curl 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
8. Encrypted HTTP--HTTPS.
If the webpage is transmitted through the HTTPS protocol encrypted by OpenSSL, curl can be accessed directly:
Curl https://that.secure.server.com
9. HTTP authentication.
If the HTTP address is authenticated by the certificate and the certificate is local, use curl as follows:
Curl-e mycert. pem https://that.secure.server.com
Reference books and notes: 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 various HTTP protocols and URL syntaxes. Here we recommend several books:
RFC 2616 defines the HTTP syntax.
RFC 2396 defines the URL syntax.
How does RFC 2109 cookie work.
RFC 1867: How to post HTTP and the format of post.
Curl is a free software, and IBM does not provide technical support for curl.
# Html/XHTML/XML Column