Understanding HTTP message headers (2)

Source: Internet
Author: User
Tags microsoft iis
Document directory
  • 1 403 Access forbidden
  • 2 404 object not found
  • 3 401 Access Denied
  • 4 302 Object Moved
  • 5 500 Internal Server Error
Understanding HTTP message header (2) Common HTTP return code in the previous article, I briefly talked about the HTTP message header format, note that there is an "HTTP/1.1 200 OK" in the HTTP message header returned by the server. Here, 200 is the Returned Code specified by HTTP, indicating that the request has been processed properly. With this return code, the browser can know what the server processes the request, and each return code has its own meaning. Several common return codes are listed here. 1 403 Access forbidden if we try to request a folder on the server and the folder on the Web server does not allow this folder column directory, this code will be returned. A complete 403 reply may be like this: (iis5.1)
HTTP/1.1 403 Access forbidden
Server: Microsoft-Microsoft IIS/5.1
Date: Mon, 06 Mar 2006 08:57:39 GMT
Connection: Close
Content-Type: text/html
Content-Length: 172 <HTML> <Body> HTTP/1.1 404 not found
Date: Mon, 06 Mar 2006 09:03:14 GMT
Server: Apache/2.0.55 (UNIX) PHP/5.0.5
Content-Length: 291
Keep-alive: timeout = 15, max = 100
Connection: keep-alive
Content-Type: text/html; charset = iso-8859-1 <! Doctype HTML public "-// IETF // dtd html 2.0 // en">
<HTML> <Title> 404 Not found </title>
</Head> <body>
<H1> not found <P> the requested URL/notexist was not found on this server. </P>
<HR>
<Address> Apache/2.0.55 (UNIX) PHP/5.0.5 server at localhost port 8080 </address>
</Body> HTTP/1.1 401 Access Denied
Server: Microsoft-Microsoft IIS/5.1
Date: Mon, 06 Mar 2006 09:15:55 GMT
WWW-Authenticate: negotiate
WWW-Authenticate: NTLM
Connection: Close
Content-Length: 3964
Content-Type: text/html <! Doctype HTML public "-// W3C // dtd html 3.2 final // en">
<HTML dir = LTR>
......
The prompt displayed in the browser is as follows. Let's enter the user name and password: because the message body in the returned information is long, only the first two lines of content are taken. Note: If you use localhost to access the local IIS, because IE can directly obtain the identity of the current user, it will negotiate with the server directly, so no 401 prompt will be displayed.
After we enter the user name and password, the server and the client will have another two conversations. First, the client requests a public key from the server, and the server returns a public key, both of which are base64-encoded. The corresponding message is as follows (the encoding part has been processed): Get/HTTP/1.1
Accept: image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, application/X-Shockwave-flash, application/vnd. MS-Excel, application/vnd. MS-PowerPoint, application/MSWord ,*/*
Accept-language: ZH-CN
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727)
HOST: 192.168.0.55: 8080
Connection: keep-alive
Authorization: negotiate abcdefg ...... HTTP/1.1 401 Access Denied
Server: Microsoft-Microsoft IIS/5.1
Date: Mon, 06 Mar 2006 09:20:53 GMT
WWW-Authenticate: negotiate hijklmn ......
Content-Length: 3715
Content-Type: text/html <! Doctype HTML public "-// W3C // dtd html 3.2 final // en">
<HTML dir = LTR>
......
After obtaining the public key, the client uses the public key to encrypt the user name and password, and then sends the encrypted result to the server again:
Get, HTTP, 1.1
Accept: image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, application/X-Shockwave-flash, application/vnd. MS-Excel, application/vnd. MS-PowerPoint, application/MSWord ,*/*
Accept-language: ZH-CN
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727)
HOST: 192.168.0.55: 8080
Connection: keep-alive
Authorization: negotiate opqrst ...... In this way, if the verification succeeds, the server will send the request content, that is, the website that prohibits anonymous access will go through three requests to see the page. However, because the client browser has cached the public key, the verification information can be sent directly when another page on the website is requested again in the same browser window, so that an interaction can be completed. 4 302 anyone who has used ASP for Object Moved knows that there are at least two methods for page redirection in ASP: redirect and transfer. The second difference is that redirect is client redirection, while transfer is server-side redirection. How are they implemented through the HTTP message header?
Let's take a look at the transfer example:
For example, ASP file 1. asp only has one row
<% Server. Transfer "1.htm" %>
HTML file 1.htm also has only one line:
<P> This is 1.htm</P>
If we request 1.aspfrom a browser, the sent request is:
GET/1. asp HTTP/1.1
Accept :*/*
Accept-language: ZH-CN
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727)
HOST: localhost: 8080
Connection: keep-alive
COOKIE: aspsessionidacctrttt = pkkdjopbakmambnanipifdap note that the requested file is indeed 1.asp, and the response is:
HTTP/1.1 200 OK
Server: Microsoft-Microsoft IIS/5.1
Date: Mon, 06 Mar 2006 12:52:44 GMT
X-powered-by: ASP. NET
Content-Length: 20
Content-Type: text/html
Cache-control: Private <p> This is 1.htm</P>
It is not hard to see that the server has already implemented page redirection through the server. Transfer statement, and the client has no idea about this. What appears to be the result of 1. asp on the surface.
If you change the content of 1. asp:
<% Response. Redirect "1.htm" %>
Request 1.aspagain. The sent request does not change, but the response is changed:
HTTP/1.1 302 Object Moved
Server: Microsoft-Microsoft IIS/5.1
Date: Mon, 06 Mar 2006 12:55:57 GMT
X-powered-by: ASP. NET
Location: 1.htm
Content-Length: 121
Content-Type: text/html
Cache-control: Private <Body> GET/1. htm HTTP/1.1
Accept :*/*
Accept-language: ZH-CN
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727)
HOST: localhost: 8080
Connection: keep-alive
If-modified-since: Thu, 02 Mar 2006 06:50:13 GMT
If-None-Match: "b224758ec53dc61: 9f0"
COOKIE: aspsessionidacctrttt = pkkdjopbakmambnanipifdaphttp/1.1 200 OK
Server: Microsoft-Microsoft IIS/5.1
X-powered-by: ASP. NET
Date: Mon, 06 Mar 2006 12:55:57 GMT
Content-Type: text/html
Accept-ranges: bytes
Last-modified: Mon, 06 Mar 2006 12:52:32 GMT
Etag: "76d85bd51c41c61: 9f0"
Content-Length: 20 <p> This is 1.htm</P>
Obviously, although the two redirection methods seem to have similar results, their implementation principles are quite different. 500 internal server error500 error occurs when the server program has an error, for example, ASP program is
<% If %>
Obviously this program is not complete, so the result is:
HTTP/1.1 500 Internal Server Error
Server: Microsoft-Microsoft IIS/5.1
Date: Mon, 06 Mar 2006 12:58:55 GMT
X-powered-by: ASP. NET
Content-Length: 4301
Content-Type: text/html
Expires: Mon, 06 Mar 2006 12:58:55 GMT
Set-COOKIE: aspsessionidacctrttt = alkdjopbppknpcnoepcnoopd; Path =/
Cache-control: Private <! Doctype HTML public "-// W3C // dtd html 3.2 final // en"> <HTML dir = LTR>
...... The server sent Error 500, and later explained the cause of the error through HTML.

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.