You are on page 1of 12

In this lecture, we will discuss…

HTTP Basics
What is HTTP?

HyperText  Transfer  Protocol  


²  Based on request/response stateless protocol
•  Client opens connection to server
•  Client sends HTTP request for a resource
•  Server sends HTTP response to the client (w/resource)
•  Client closes connection to server
Identifying Resources on the Web

URN:  Uniform  Resource  Name  


²  Uniquely identifies resource or name of resource
²  Does not tell us how to get the resource

example:
“HTML/CSS/Javascript/Web Developers/Yaakov/Chaikin”
Identifying Resources on the Web

URI:  Uniform  Resource  Iden;fier  


²  Uniquely identifies resource or location of resource
²  Does not necessarily tell us how to get the resource

example:
/official_web_site/index.html
Identifying Resources on the Web

URL:  Uniform  Resource  Locator  


²  Form of URI that provides info on how to get resource

example:
http://www.mysite.com/official_web_site/index.html
HTTP Request Structure (GET)

GET /index.html?firstName=Yaakov HTTP/1.1

Method   URI  String   Query  String   HTTP  version  

name/value  pairs  separated  by  &  


Example:  ?first=Yaakov&last=Chaikin  
HTTP Methods

²  GET
•  Retrieves the resource
•  Data is passed to server as part of the URI
§  I.e., query string
²  POST
•  Sends data to server in order to be processed
•  Data is sent in the message body
²  More methods not covered here
HTTP Request Structure (POST)

POST /index.html HTTP/1.1


Host: coursera.org request  
Accept-Charset: utf-8 headers  

firstName=Yaakov…

… message  
body  
HTTP Response Structure

Separated  by  a  
single  space  

HTTP/1.1 200 OK

HTTP   Response   English  phrase  


version   status  code   describing  
status  code  
Typical HTTP Response
HTTP/1.1 200 OK

Date: Tue, 11 Aug 2004 19:00:01 GMT

Content-Type: text/html

<html>

<body>

<h1>Secret to gaining weight REVEALED!</h1>
<p>Develop Coursera courses after work at night
while eating sweets to keep yourself awake!</p>

</body>

</html>
Some Response Status Codes

²  200 OK
•  Ok, here is the content you requested
²  404 Not Found
•  Server can’t find the resource requested
²  403 Forbidden
•  Unauthenticated client tried to access a secure resource
²  500 Internal Server Error
•  Some unhandled error was raised on the server
Summary

²  Need to understand the basics of HTTP protocol


²  GET method sends data to server as part of the URL
²  POST method sends data as part of message body
²  Response codes: 200, 404, 500, etc.

You might also like