013_ Practice HTTP206 Status: Partial content and scope requests

Source: Internet
Author: User
Tags ranges

The status code in the HTTP 2xx range indicates: "The request sent by the client has been accepted by the server and successfully processed". http/1.1 OK is the standard response after the HTTP request succeeds, and when you open www.cyberciti.biz in the browser, you usually get a 200 status code. The http/1.1 206 status code indicates that "the client fetched some of the data from the resource by sending a range request header range". This request is typically used to:

    1. Learn HTTP headers and states.
    2. Solve the network problem.
    3. Solve large file download problems.
    4. Troubleshoot CDN and raw HTTP server issues.
    5. Use tools such as lftp,wget,telnet to test the power-down continuation.
    6. The test divides a large file into multiple parts and downloads it simultaneously.
Find out if the remote server supports HTTP 206

First you need to know the file size and whether the remote server supports HTTP 206 requests. Use the Curl command to view HTTP headers for any resource, and use the following Curl command to send a head request:

$ curl -I http://s0.cyberciti.org/images/misc/static/2012/11/ifdata-welcome-0.png

The output is:

http/1.0 OK
Content-type:image/png
content-length:36907
Connection:keep-alive
Server:nginx
date:wed, 00:44:47 GMT
X-whom:l3-com-cyber
Cache-control:public, max-age=432000000
Expires:fri, Jul 2026 00:44:46 GMT
Accept-ranges:bytes
ETag: "278099835"
Last-modified:mon, 23:06:34 GMT
age:298127

There are two request headers that we are more concerned about:

Accept-Ranges: bytes-This 响应头表明服务器支持Range请求 , and the units supported by the server are bytes (This is also the only available unit). We also know that the server supports the continuation of breakpoints and supports simultaneous downloading of multiple parts of a file, meaning that the download tool can use the range request to speed up the download of the file. Accept-Ranges: none The response header indicates that the server does not support range requests.

Content-Length: 36907- Content-Length响应头表明了响应实体的大小,也就是真实的图片文件的大小是 36907 bytes (37K).

How do I send a range request header?

Now that you know that the server that contains the image supports the range request, you need to send a GET request with a range request header:

range:bytes=0-1024

The complete request data should look like this. The first line is:

You then need to send the host request header to specify the hosts and port numbers on which the requested resource resides:

Host:s0.cyberciti.org

Finally, the range request header to be sent specifies the byte ranges you want:

Using the Telnet command

The Telnet command allows you to use the Telnet protocol to communicate with a remote host (server). All UNIX-like operating systems and Ms-windows contain Telnet clients. Start the Telnet client and go to the Telnet prompt to execute the command:

Telnet Your-server-name-here www
Telnet Your-server-name-here 80

To connect to the remote server s0.cyberciti.org by port number 80, enter:

The output is:

Trying 54.240.168.194 ...
Connected to D2m4hyssawyie7.cloudfront.net.
Escape character is ' ^] '.

In this example, using a range request (0-1024 bytes) To request the/images/misc/static/2012/11/ifdata-welcome-0.png file on s0.cyberciti.org, enter:

Get/images/misc/static/2012/11/ifdata-welcome-0.png http/1.1
Host:s0.cyberciti.org
range:bytes=0-1024

The output is:

In

    1. Zone 1-get requests and request headers.
    2. Zone 2-206 status and response header.
    3. Zone 3-binary data.
Using the Curl command

The Curl command is a tool for exchanging data with a remote server. It supports range requests on the Http/ftpsftp/file protocol, in the following example, using a two-segment range to request a remote file ifdata-welcome-0.png, Then use the Cat command to merge two pieces of data into the full file:

Curl  --header "range:bytes=0-20000" Http://s0.cyberciti.org/images/misc/static/2012/11/ifdata-welcome-0.png- o part1
Curl --header "range:bytes=20001-36907" http://s0.cyberciti.org/images/misc/static/2012/11/ Ifdata-welcome-0.png-o Part2
Cat Part1 Part2 >> test1.png
Gnome-open Test1.png

You can also use the-r option (you can also add the-V option to view the request header and the response header):

Curl-  R 0-20000 Http://s0.cyberciti.org/images/misc/static/2012/11/ifdata-welcome-0.png-o part1
Curl- R 20001-36907 Http://s0.cyberciti.org/images/misc/static/2012/11/ifdata-welcome-0.png-o part2
Cat Part1 Part2 >> test2.png
Gnome-open Test2.png
Summarize

This article discusses how to view the HTTP header and response status for a request. You can use a range request to fragment a large file, and if the specified offset is valid, the server returns an HTTP 206 status code. If the offset is not valid, the server returns an HTTP 416 status code ( The request scope is not met.)

Reference:https://www.cnblogs.com/ziyunfei/archive/2012/11/18/2775499.html

013_ Practice HTTP206 Status: Partial content and scope requests

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.