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

Source: Internet
Author: User
Tags uppercase letter

Article Source:

Curl Command Detailed:

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


-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
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http:// ">
<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. "/>
Welcome-Shanghai Teng Yi


Example two viewing response header information

[Email protected] ~]# curl-i
http/1.1 OK
Last-modified:tue, Sep 03:19:11 GMT
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

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



Curl Download

Download 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 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:// "

3. Monitoring of Site availability
Curl-o/dev/null-s-W%{http_code} ""

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} '

Curl-o/dev/null-s-W '%{http_code} '


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} '

% 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} '

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 Usage Daquan

-x Specifies the access IP and port number


-I just take the HTTP header of the file


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

CURL-E ""/http/

-h to construct the HTTP header you want

Curl-h "X-forward-for:″

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


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

Curl-o file.html

Download index.html file,-O is uppercase letter


Curl submits user name and password

Curl Http://name:[email protected]
Curl-u name:passwd

-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

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: 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.