Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 HTTP and some other odds and ends Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.

Similar presentations


Presentation on theme: "1 HTTP and some other odds and ends Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park."— Presentation transcript:

1 1 HTTP and some other odds and ends Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park

2 2 For your amusement Original 1991 HTTP spec http://www.w3.org/Protocols/HTTP/AsImplemented.html barely one page As defined in 1992 http://www.w3.org/Protocols/HTTP/HTTP2.html

3 3 HTTP GET Request HTTP GET Request GET request HTTP/1.0 or GET request HTTP/1.1 Followed by any number of other HTTP request lines Followed by a blank line

4 4 Other sample headers Accept: */* Accept-Language: en Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/417.9 (KHTML, like Gecko) Safari/417.8 Connection: keep-alive Host: localhost:8888

5 5 Other HTTP requests HEAD just requests information about a page (size, last time it was modified) body of page not sent POST should be used for any HTTP request that will modify state should always be OK to repeat a GET request, not so with POST parameters sent in body of request, after blank line, rather than in URL

6 6 Obscure HTTP requests The HTTP protocol defines some additional requests (e.g., DELETE) that almost nobody uses or supports

7 7 HTTP Response status line any number of response headers a blank line response data (binary format)

8 8 HTTP Response Status HTTP/1.0 200 OK the http version the server is speaking a numeric status code a string description of the reason for the status

9 9 HTTP response headers Sample: Date: Wed, 01 Mar 2006 03:27:02 GMT Server: Apache Accept-Ranges: bytes Connection: close Content-Type: text/html; charset=ISO-8859-1 Content-Type is the only one that is really required

10 10 HTTP body Body needs to be treated as binary data If you open a JPEG file as a text file, read lines of text from it and print them to a writer wrapped around the socket output stream it will not work So, how do you handle this?

11 11 Mixed text/binary output OutputStream Network PrintWriter w.println(“HTTP/1.0 200 OK”); PrintWriter w = new PrintWriter(out); // PrintWriter autoflushes w.println(“Content-Type: text/html”); // just one byte of data for this example out.write(data); // PrintWriter autoflushes again w.println(); out.close(); Text bytes

12 12 One more thing... Reflection The ability of Java programs to look at what classes, methods and fields are defined and manipulate/invoke/access classes/methods/fields specified by strings rather than by compiled code Among other things allows your code to load/invoke code written after your code was compiled and shipped has to have access to new code has to get names of code to invoke

13 13 Class objects For each class in Java, there is a Class object associated with that class Use x.getClass() to get Class object associated with object referenced by x Use, for example, String.class to get Class object associated with class String Use Class.forName(s) to get the class named by the String s

14 14 newInstance() Given a Class object, you can create an instance of that class by invoking newInstance() on the Class object you will usually want to cast the result to some type Creates the instance using the void constructor for the class. Runtime error if there is no accessible void constructor


Download ppt "1 HTTP and some other odds and ends Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park."

Similar presentations


Ads by Google