Curl command to get response codes for Web sites

Source: Internet
Author: User
Tags remote ftp server response code

Curl command A lot of parameters, bloggers have not used many. Found today can be used with the-w parameter is very useful.


-w:--write-out, the function is the output point what. The-w parameter of curl is used to output the contents of the specified format to standard output after a complete and successful operation. The output format consists of a normal string and any number of variables, the output variable needs to be in accordance with the format of%{variable_name}, if you need to output%,double, that is, percent, at the same time, \ n is a newline, \ r is the carriage return, \ t is the tab. Curl substitutes the appropriate values for the variables in the output format, and all the available variables are as follows:

url_effective finally gets the URL address, especially if the address you assign to curl has a 301 jump, and continues tracking through-L.

http_code HTTP status code, such as 200 success, 301 turn, 404 Not Found, 500 server error, etc. (The numerical response code that is found in the last retrieved HTTP (s) or FTP (s) transfer. In 7.18.2 the alias Response_code is added to show the same info.)

Http_connect The numerical code that is found in the last response (from a proxy) to a Curl CONNECT request. (Added in 7.12.4)

time_total total time, in seconds. Accurate to three digits after the decimal point. (The total time, in seconds, then the full operation lasted. The time would be displayed with millisecond resolution.)

Time_namelookup DNS resolution time, from the start of the request to the time that DNS resolution is complete. (The time, in seconds, it took from the start until the name of resolving was completed.)

Time_connect connection time, from start to establish TCP connection to complete the time spent, including the front DNS resolution time, if you need to simply get the connection time, with this time_connect time minus the front time_namelookup time. The following is the same, no longer repeat. (The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) is completed.)

Time_appconnect Connection Establishment completion time, such as SSL/SSH, etc. to establish a connection or to complete three handshake time. (The time, in seconds, it took from the start until the ssl/ssh/etc Connect/handshake to the remote host was completed. (Added in 7.19.0))

time_redirect   redirect time, including several redirected DNS resolution, connection, pre-transfer, transfer time before the last transmission. (The time, in seconds, it took for all redirection steps include name lookup, connect, Pretransfer and transfer before the Final transaction was started. Time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3))

time_starttransfer Start transfer time. The time it took for the WEB server to return the first byte of data after the request was made (the times, in seconds, the it took from the start until the initial byte was just on to be Tran Sferred. This includes Time_pretransfer and also the time of the server needed to calculate the result.)

size_download Download size. (The total amount of bytes that were downloaded.)

size_upload upload size. (The total amount of bytes that were uploaded.)

Size_header The size of the header downloaded (the total amount of bytes of the downloaded headers.)

The size of the size_request request. (The total amount of bytes, were sent in the HTTP request.)

speed_download Download speed, units-bytes per second. (The average download speed, the curl measured for the complete download. Bytes per second.)

speed_upload upload speed, units-bytes per second. (The average upload speed, the curl measured for the complete upload. Bytes per second.)

Content_Type is content-type, needless to say, this is a visit to my blog home page returned results example (text/html; charset=utf-8); (The Content-type of the Requested document, if there is any.)

num_connects Number of new connects made in the recent transfer. (Added in 7.12.3)

num_redirects Number of redirects that were followed in the request. (Added in 7.12.3)

Redirect_url When a HTTP request is made without-l to follow redirects, this variable would show the actual URL a redirect would take To. (Added in 7.18.2)

Ftp_entry_path The initial path Libcurl ended up and when logging on to the remote FTP server. (Added in 7.15.4)

ssl_verify_result SSL authentication results, return 0 indicates successful authentication. (The result of the SSL Peer certificate verification is requested. 0 means the verification was successful. (Added in 7.19.0))


Example: Get the response code for the Http://baidu.com Web site with the Curl command

[Email protected]:~# curl-i-s-w "%{http_code}\n"-o/dev/null http://baidu.com200

-I: Get header information,

-s:silent mode, without this argument, the execution of the command is the result

[email protected]:~# curl -i  -w  "%{http_code}\n"  -o /dev/null  Http://baidu.com    % Total    % Received % Xferd   Average Speed   Time    Time      time  current                                   Dload  Upload   Total   Spent    Left   speed  0    81    0     0     0     0      0       0 --:--:-- --:--:-- --:--:--     0200

-O: Save the file as the file name specified on the command line, we are here to output the result directly to/dev/null, and if you do not add the-o parameter, the output is as follows:

[Email protected]:~# curl-i-W '%{http_code}\n ' http://baidu.com http/1.1 Okdate:sun, 2016 07:57 : Gmtserver:apachelast-modified:tue, 13:48:00 gmtetag: "51-47cf7e6ee8400" Accept-ranges: Bytescontent-length:81cache-control:max-age=86400expires:mon, 07:57:46 gmtconnection: keep-alivecontent-type:text/html200






This article from "Zengestudy" blog, declined reprint!

Curl command to get response codes for Web sites

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.