The Shell Curl command in Linux gets the HTTP status code--------powerful network Transfer tool

Source: Internet
Author: User
Tags uppercase letter

Article Source: http://dbajun.iteye.com/blog/1813801

Curl Command Detailed: http://blog.sina.com.cn/s/blog_94cf845f0102w8vt.html

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.

Common parameters

There are many parameters to the Curl command, and here are just a list of those I used, especially in shell scripts.

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

-d/--data/--data-ascii <data> Specify the contents of the Post

--retry <num> Specify the number of retries

-e/--referer <URL> Specify a reference address

-i/--head only returns header information, using head request

Use example one to get the specified Web page

[Email protected] ~]# Curl http://www.sunrisecorp.net/
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "/>
<meta name= "title" content= "Welcome to Shanghai Teng Yi"/>
<meta name= "keyword" content= "Shanghai Teng One, integrated communications, e-commerce, voice communications, data communications, base station project outsourcing hosting, Internet of Things, website building, e-commerce solutions, mobile Web, SMS, MMS, call center, multiparty conferencing, PBX, IVR, e-commerce planning scheme, equipment generation, network optimization, communication engineering, telecom value added, 3G "/>
<meta name= "description" content= "Shanghai Teng an Information Technology Co., Ltd. focused on telecom value-added, communications engineering, e-commerce and other fields, with nearly ten years of experience. "/>
<title>
Welcome-Shanghai Teng Yi
</title>

</body>

Example two viewing response header information

[Email protected] ~]# curl-i http://www.sunrisecorp.net/
http/1.1 OK
server:apache-coyote/1.1
Accept-ranges:bytes
etag:w/"17801-1285643951000"
Last-modified:tue, Sep 03:19:11 GMT
Content-type:text/html
content-length:17801
Date:tue, Oct 12:49:20 GMT

[Email protected] ~]#

===========================================================================

We can customize the output of curl by using the-w parameter of Curl

The code is as follows
# curl-i-M 10-o/dev/null-s-w%{http_code} IP address or URL
The above output does not include line breaks, and if you need to wrap, add \ n
The code is as follows
# curl-i-M 10-o/dev/null-s-w%{http_code} IP address or URL
200

# curl-i-M 10-o/dev/null-s-w%{http_code} "\ n" IP address or URL

200

============================================================================

Curl Download

Download Win32or64.zip on official website, download

Download the missing DLL file

Use DOS to go to the Unzip directory and run the Curl command

Command instance

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 "

3. Monitoring of 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 ........

Monitoring site homepage Download time:

Curl-o/dev/null-s-W '%{time_total} ' http://www.miotour.com

Curl-o/dev/null-s-W '%{http_code} ' http://www.miotour.com

Curl-o/dev/null-s-W%{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total} http://www.miotour.com

Results: 2.547

-s silent output, without the-s word is the following situation, which is not required in the case of scripts and other information.

[[email protected] ~]$ Curl-o/dev/null-w '%{time_total} ' http://www.miotour.com

% total% Received% xferd Average speed Time Time current

Dload Upload Total spent

100 67770 0 67770 0 0 19228 0–:–:–0:00:03–:–:–20705

Results: 3.524

Monitoring the first page of the time indicators:

Curl-o/dev/null-s-W '%{time_connect}:%{time_starttransfer}:%{time_total} ' http://www.miotour.com

Results: 0.244:1.044:2.672

Time Indicator Explanation:

Time_connect the time it took to establish a TCP connection to the server

Time_starttransfer the time it takes for the WEB server to return the first byte of data after making a request

Time_Total the time it took to complete the request

After the request is made, the time it takes for the WEB server to process the request and start sending the data back is

(Time_starttransfer) 1.044-(time_connect) 0.244 = 0.8 seconds

The time it takes for the client to download data from the server is

(time_total) 2.672-(time_starttransfer) 1.044 = 1.682 seconds

Specify a specific host IP address to access the Web site

Curl-x 61.135.169.105:80 http://www.baidu.com

Curl-x 61.135.169.125:80 http://www.baidu.com

Curl Usage Daquan

-x Specifies the access IP and port number

Curl-x 192.168.1.1:80 http://www.miotour.com

-I just take the HTTP header of the file

Curl-i-X 192.168.1.1:80 http://www.miotour.com

Using the Referer chain, you can use-E to set

CURL-E "http://www.qiecuo.org"/http/www.miotour.com-v-I.

-h to construct the HTTP header you want

Curl-h "X-forward-for:8.8.8.8″http://www.miotour.com-v-I.

Curl feedback time, such as connection time, download time and other information

Curl-w%{time_connect}:%{time_starttransfer}:%{time_total}-s-o/dev/null

Save a file to your hard disk, named file.html

Curl-o file.html http://www.miotour.com/index.html

Download index.html file,-O is uppercase letter

Curl-o http://www.miotour.com/index.html

Curl submits user name and password

Curl Http://name:[email protected]
Curl-u name:passwd http://www.miotour.com

-B "Cookie" This parameter is used to construct a request to carry a cookie

The Shell Curl command in Linux gets the HTTP status code--------powerful network Transfer tool

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.