Presentation is loading. Please wait.

Presentation is loading. Please wait.

PL-IV- Group A HTTP Request & Response Header

Similar presentations


Presentation on theme: "PL-IV- Group A HTTP Request & Response Header"— Presentation transcript:

1 PL-IV- Group A HTTP Request & Response Header
By Prof. B.A.Khivsara Assistant Prof. Department of Computer Engg. SNJB’s KBJ COE, Chandwad

2 OUTLINE HTTP Working HTTP Messages Program in Java Introduction

3 Web and HTTP First some jargon Web page consists of objects
Object can be HTML file, JPEG image, Java applet, audio file,… Web page consists of base HTML-file which includes several referenced objects Each object is addressable by a URL Example URL: host name path name

4 HTTP overview HTTP: hypertext transfer protocol
Web’s application layer protocol client/server model client: browser that requests, receives, “displays” Web objects server: Web server sends objects in response to requests HTTP uses port no 80 HTTP request PC running Explorer HTTP response HTTP request Server running Apache Web server HTTP response Mac running Navigator

5 HTTP overview (continued)
Uses TCP: client initiates TCP connection (creates socket) to server, port 80 server accepts TCP connection from client HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) TCP connection closed HTTP is “stateless” server maintains no information about past client requests 2: Application Layer

6 OUTLINE HTTP Working HTTP Messages Program in Java

7 HTTP Message Formats Two types of message HTTP Request message
HTTP Response Message

8 HTTP request message: general format

9 HTTP request message Example
ASCII (human-readable format) request line (GET, POST, HEAD commands) GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr (extra carriage return, line feed) header lines Carriage return, line feed indicates end of message

10 Uploading form input Post method: Web page often includes form input
Input is uploaded to server in entity body GET method: Uses GET method Input is uploaded in URL field of request line: Example - GET Method (

11 HTTP Methods The GET method requests the server to send the page . The page is suitably encoded in MIME. The vast majority of the requests on the web are GETs. GET filename HTTP/1.1 Where filename is the resource name to be fetched and 1.1 is the protocol version being used The HEAD method just asks for the message header, without the actual page. This method can be used to get a page’s time of last modification, to collect information for indexing purposes, or just to test an URL for validity The PUT method is the reverse of GET. Instead of reading a page, it writes a page. This method makes it possible to build a collection of web pages on a remote web server. The body of the request contains the page. It may be encoded using MIME, in which case, the lines following the PUT might include Content-Type and authentication headers to prove that the caller indeed has permission to perform the operation POST is similar to PUT. It too, bears an URL, but instead of replacing the existing data, it appends it to any existing data. Posting a message to a newsgroup or adding a file to a bulletin board are example of the usage. DELETE does what you expect: deletes a page from a remote web server; authentication and permissions play a major role here. There is no guarantee that a DELETE operation is successful since even if the remote web server is willing to delete a page, the file permissions may be set in such a way that the server process doesn’t have rights to do it. TRACE method is used for debugging. It instructs the server to send back the request. This is useful when requests are not processed correctly and the client wants to know it sent the proper request. CONNECT – is not used at the moment OPTIONS – provides a way for the client to query the server about its properties or those of a specified file DELETE does what you expect: deletes a page from a remote web server; authentication and permissions play a major role here. There is no guarantee that a DELETE operation is successful since even if the remote web server is willing to delete a page, the file permissions may be set in such a way that the server process doesn’t have rights to do it. TRACE method is used for debugging. It instructs the server to send back the request. This is useful when requests are not processed correctly and the client wants to know it sent the proper request. CONNECT – is not used at the moment OPTIONS – provides a way for the client to query the server about its properties or those of a specified file The PUT method is the reverse of GET. Instead of reading a page, it writes a page. This method makes it possible to build a collection of web pages on a remote web server. The body of the request contains the page. It may be encoded using MIME, in which case, the lines following the PUT might include Content-Type and authentication headers to prove that the caller indeed has permission to perform the operation The GET method requests the server to send the page . The page is suitably encoded in MIME. The vast majority of the requests on the web are GETs. GET filename HTTP/1.1 Where filename is the resource name to be fetched and 1.1 is the protocol version being used The HEAD method just asks for the message header, without the actual page. This method can be used to get a page’s time of last modification, to collect information for indexing purposes, or just to test an URL for validity POST is similar to PUT. It too, bears an URL, but instead of replacing the existing data, it appends it to any existing data. Posting a message to a newsgroup or adding a file to a bulletin board are example of the usage.

12 HTTP response message: general format

13 HTTP response message example
status line (protocol status code status phrase) HTTP/ OK Connection close Date: Thu, 06 Aug :00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/html data data data data data ... header lines data, e.g., requested HTML file

14 Different Header fields in HTTP Response Message
Connection Date Expires Cache-Control Content-Encoding Content-Language Content-Length Content-Location ………. And many more

15 HTTP response status codes
A few sample codes: 200 OK request succeeded, requested object later in this message 301 Moved Permanently requested object moved, new location specified later in this message (Location:) 400 Bad Request request message not understood by server 404 Not Found requested document not found on this server 505 HTTP Version Not Supported

16 HTTP Version differences
Have only 16 status codes Provides only basic authentication Uses Non persistent connection RTT is more so bandwidth waste is vast Stateless Supports only GET POST and HEAD method HTTP/1.1 Have introduced new 24 status code Provides strong authentication Uses Persistent connection RTT is less so bandwidth utilization is good Uses cookies as state management mechanism Supports GET, POST, HEAD,PUT and DELETE

17 Web caches (proxy server)
Goal: satisfy client request without involving origin server user sets browser: Web accesses via cache browser sends all HTTP requests to cache object in cache: cache returns object else cache requests object from origin server, then returns object to client origin server HTTP response Proxy server HTTP request client HTTP request HTTP response client origin server 2: Application Layer

18 OUTLINE HTTP Working HTTP Messages Program in Java Introduction

19 Program in Java import java.net.*; import java.util.*;
public class HTTPResponseHeader { public static void main(String[] args) { try {

20 Program in Java URLConnection conn = obj.openConnection();
URL obj = new URL(" URLConnection conn = obj.openConnection(); Map<String, List<String>> map = conn.getHeaderFields(); System.out.println("Printing Response Header for URL:” + obj.toString() + "\n");

21 Program in Java } System.out.println(entry.getKey() + " : " + entry.getValue()); { for (Map.Entry<String, List<String>> entry : map.entrySet()) e.printStackTrace();} catch (Exception e) {

22 Sample Output of Program


Download ppt "PL-IV- Group A HTTP Request & Response Header"

Similar presentations


Ads by Google