Curl Installation and use

Source: Internet
Author: User
Tags curl

Curl can be viewed as a command line browser

1. Open the GZIP request

# curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte

2, monitoring the response time of the Web page

# curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.kklinux.com"
    1. Monitoring site Availability
# curl -o /dev/null -s -w %{http_code} "http://www.kklinux.com"

4. Request with http1.0 protocol (default is http1.1)

Curl-0 ........
1) Read Web page

$ curl linuxidc.com">http://www.linuxidc.com

2) Save Web page
  

$ curl http://www.linuxidc.com > page.html $ curl -o page.html http://www.linuxidc.com

3) Used proxy server and its port:-X
  

$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

4) Use cookies to record session information

$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

Option:-D is to store the cookie information in the HTTP response in a special file, so that when the page is saved to page.html, the cookie information is stored in the cookie0001.txt.

5) So, how do you continue to use the cookie information you left last time you visit?
Use option to append the last cookie information to the HTTP request:-B

$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

6) The browser information is arbitrarily assigned to its own browser information stated in this visit:-A

# curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com

In this way, the server side access to the requirements, will think you are a running on the Windows2000 on the IE6.0, Hei heh hey, in fact, maybe you use an Apple machine it! and "mozilla/4.73 [en] (X11; U Linux 2.2; i686 "You can tell each other that you are running Linux on a PC, using Netscape 4.73, hehe.

7) Another common restriction method on the server side is to check HTTP access referer. For example, you first visit the homepage, and then access the download page specified in the, this second access to the Referer address is the first successful access to the page address. Curl provides us with the option to set Referer:-E

# curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.yahoo.com" -o page.html -D cookie0001.txthttp://www.yahoo.com

In this way, you can cheat each other's server, you are from the mail.yahoo.com click on a chain took over, oh hehe

8) Curl Download file

Just now, download the page to a file, you can use-o, download the same file.

curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG

9)
Come again, we continue to explain the download!

curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG

The resulting download is

~zzh/001.JPG~zzh/002.JPG...~zzh/201.JPG~nick/001.JPG~nick/002.JPG...~nick/201.JPG

9) continue to download
We usually on the Windows platform, flashget such a tool can help us to block parallel download, but also can be disconnected to continue transmission.

For example, we download screen1. JPG, and suddenly dropped, so we can start the continuation.

# curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG

Block download, we can use this option:-R
Examples Show
For example, we have a Http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 to download (Miss Zhao's telephone recitation:D )
We can use this command:

# curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &# curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &# curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &# curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3

This will allow you to download the tiles.
But you need to merge the broken files yourself.
If you use UNIX or apples, use cat zhao.part* > Zhao.mp3 to
If the use of Windows, with copy/b to solve it, hehe
The above is the HTTP protocol download, in fact, FTP can also be used.
Usage,

# curl -u name:passwd ftp://ip:port/path/file

or familiar to everyone.

# curl ftp://name:[email protected]:port/path/file

10) the option to upload is-t

For example, we send a file to ftp:

# curl -T localfile -u name:passwd ftp://upload_site:port/path/

Of course, uploading files to an HTTP server can also be as follows:

# curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi

Note that at this time, the protocol used is the put method of HTTP
Just said put, hey, naturally let the old service think up the other several methos have not said it!
Neither get nor post can be forgotten.

HTTP Submit a form, more commonly used is the post mode and get mode, get mode what option is not required, just to write the variable in the URL inside it can be

Like what:

#curl http://www.yahoo.com/login.cgi?user=nickwolfe&password=12345

The option for Post mode is-D
Like what:

# curl -d "user=nickwolfe&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/~zzh/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/~zzh/up_file.cgi
Ro-Ro said so much, actually curl has a lot of tricks and usage

For example, when you use local certificates for HTTPS, you can

# curl -E localcert.pem https://remote_server

For example, you can also use curl to check the dictionary through the Dict protocol ~~~~~

# curl dict://dict.org/d:computer

Curl Installation and use

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.