Shell's Common Command curl:-w,–write-out parameter explanation

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

As the name implies, Write-out's role is to output something. 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_pretransfer The time from the start to the ready transfer. (The time, in seconds, it took from the start until the file transfer is just about to begin. This includes all Pre-transfer commands and negotiations that is specific to the particular protocol (s) involved.)

Time_redirect redirect time, including several redirected DNS resolutions, connections, pre-transmissions, and transfer times 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 your 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))

Attention:

1. If you use the-w parameter multiple times, output in the last format.

2, in the use of the above variables, pay attention to the following parentheses in the Added in XXX, which represents the minimum version required to support the variable curl, see Curl version using Curl-v. If the version is not enough, curl will prompt you for an error similar to the following.

Curl:unknown–write-out variable: ' Redirect_url '


A case of curl-w usage

Check HTTP status for a batch of URLs: Cat Url.txt|while Read line, do curl-i $line-M 5–connect-timeout 5-o/dev/null-s-W "$line"%{http _code} "\ n"; Done>ok.txt

Original address: http://seofangfa.com/shell/curl-w-write-out.html

Shell's Common Command curl:-w,–write-out parameter explanation

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.