21 Feb 2014

HTTP Request Headers I (Headers only)


Headers:



1.      Accept:-

-          This header specifies the MIME types that the browser or other clients can handle.

-          A servlet that can return a resource in more than one format can examine the Accept header to decide which format to use.

Ex - request.getHeader ("Accept");


2.      Accept- Charest:-

-          This header indicates the character sets the browser can use.

Ex - request.getHeader ("Accept-Charest");

3.      Authorization:- 
 
-          This header is used by clients to identify themselves when accessing password-protected Web pages.

4.      Connection:- 

-          This header indicates whether the client can handle persistent HTTP connections. Persistent connections permit the client or other browser to retrieve multiple files with a single socket Connection.

5.      Cookie:-


-          This header returns cookies to servers that previously sent them to the browser.

Ex- request.getHeader ("Accept-Charest");

6.      Host:-


-          This header indicates the host and port as given in the original URL.

Ex- request.getHeader ("Host");


7.      Referer:-


-       This header indicates the URL of the referring Web page.

Ex- request.getHeader ("Referer");

8.      Accept-Language:-


-          This header specifies the client's preferred languages in case the servlet can produce results in more than one language.

-          The value of the header should be one of the standard language codes such as en, en-us, da, etc.


9.      If-Modified-Since:-

-          This header indicates that the client wants the page only if it has been changed after the specified date.


-          The server sends a 304 (Not Modified) header if no newer result is available.

Ex- request.getHeader ("If-Modified-Since");

10.  If-Unmodified-Since:-

-          This header is the reverse of If-Modified-Since it specifies that the operation should succeed only if the document is older than the specified date.

Ex- request.getHeader ("If-Unmodified-Since");


11.  User-Agent:-


-          This header identifies the browser or other client making the request and can be used to return different content to different types of browsers.

-          However, the User-Agent header is quite useful for distinguishing among different categories of client.

-          For example, Japanese developers might see whether the User-Agent is an Imode cell phone, a Skynet cell phone, or a Web browser.


Ex- request.getHeader ("User-Agent");


12.  Accept-Encoding:-

-          Using an encoding the browser doesn't understand results in incomprehensible pages. 

-          Consequently, it is critical that you explicitly check the Accept-Encoding header before using any type of content encoding. 

-     Values of gzip or compress are the two most common possibilities.

13.  Content-Length:-


-          This header is applicable only to POST requests and gives the size of the POST data in bytes.


Ex- request.GetIntHeader ("Content-Length");

HTTP Request Header II (Methods)


·         Reading Request Headers:

                        Reading headers is straightforward; just call the get Header method of      HttpServletRequest with the name of the header.
            Header names are not case sensitive. So,
            For example, request.getHeader ("Connection") is interchangeable with 
     request.getHeader ("connection").
             Always check that the result of request.getHeader is non-null before using it.
             A few headers are so commonly used that they have special access methods in HttpServletRequest. Following is a summary.

·         get Cookies:- 
-          The get Cookies method returns the contents of the Cookie header, parsed and stored in an array of Cookie objects.

·         getAuthType and getRemoteUser:-
-          The getAuthType and getRemoteUser methods break the Authorization header into its component pieces.

·         getContentLength:-
-          The getContentLength method returns the value of the Content-Length header (as an int).

·         getContentType:-
-          The getContentType method returns the value of the Content-Type header (as a String).

·         getDateHeader and getIntHeader:-
-          The getDateHeader and getIntHeader methods read the specified headers and then convert them to Date and int values, respectively.

·         getHeaderNames:-
-          Rather than looking up one particular header, you can use the getHeaderNames method to get an Enumeration of all header names received on this particular request.

·         getHeaders:-
-          In most cases, each header name appears only once in the request. Occasionally, however, a header can appear multiple times, with each occurrence listing a separate value. Accept-Language is one such example. You can use getHeaders to obtain an Enumeration of the values of all occurrences of the header.

·         getMethod:-
-          The get Method method returns the main request method (normally, GET or POST, but methods like HEAD, PUT, and DELETE are possible).

·         getRequestURI:-
-          The getRequestURI method returns the part of the URL that comes after the host and port but before the form data. 

·         getQueryString:-
-          The getQueryString method returns the form data.

·         getProtocol:-
-          The getProtocol method returns the third part of the request line

Comments

© 2013-2016 ITTechnocrates. All rights resevered. Developed by Bhavya Mehta