- HTTP request
- request header
- response header
- response data
Before using them in a project, a few details for each is needed.
Browser Request - Server Response
Most of the user interactions with a website through a browser results into a HTTP request sent to the web server.
Example:
1. open the browser
2. open a web page
3. interact with the web page
4. the page changes:
- a part of the page changes
- the page is reloaded
- a new page is loaded
Every time the page changes, the browser sends a HTTP request to the server.
The server generates the new page and sends the new page as a response to the browser.
The browser renders the new page for the user.
A HTTP request has the following template:
HTTP request types: GET and POST
Two commonly used HTTP methods are:
GET request - Used for requesting data from the web server
POST request - Submits data to be processed to a web server
The GET Method
Query strings (name/value pairs) are sent in the URL of a GET request:
GET /test/demo_form.asp?name1=value1&name2=value2
Characteristics of GET requests:
1. GET requests can be cached
2. GET requests remain in the browser history
3. GET requests can be bookmarked
4. GET requests should never be used when dealing with sensitive data
5. GET requests have length restrictions
6. GET requests should be used only to retrieve data
The POST Method
Query strings (name/value pairs) are sent in the HTTP message body of a POST request:
POST /test/demo_form.asp HTTP/1.1
Host: demo.com
name1=value1&name2=value2
Characteristics of POST requests:
1. POST requests are never cached
2. POST requests do not remain in the browser history
3. POST requests cannot be bookmarked
4. POST requests have no restrictions on data length
BROWSER REQUEST
The following info is included in a browser request in the request header:
- request type: GET/POST
- protocol type and version (HTTP)
- URL: hostname + URI
http://wwwa.autotrader.ca/cars/bc/vancouver/?prv=BC&loc=vancouver&prx=100
request type = GET
protocol type = HTTP
port = 80
hostname = wwwa.autotrader.ca
URI = cars/bc/vancouver/?prv=BC&loc=vancouver&prx=100
Query String = prv=BC&loc=vancouver&prx=100
- client:
accept: text/html, application /xhtml+xml, .....
accept encoding: gzip, deflate, .....
accept language: en-US, en
user agent: Mozilla/5.0, apple webkit, chrome, safari
The user agent depends on the browser type and device type:
- Firefox: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
- Internet Explorer: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
- Chrome: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko Chrome/38.0.2125.104 Safari/537.36
- Nexus 7 tablet: Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.72 Safari/537.36
- Iphone 6 smartphone: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4
- cookies info
- transport:
connection info: keep alive
host name
WEB SERVER RESPONSE
The web server response has 2 parts:
Response Data
Page content sent by the web server to the browser
Response Header
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Wed, 22 Oct 2014 18:21:19 GMT
Content-Type: text/html;charset=utf-8
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: agency_id=BC-VANCOUVER; path=/
Set-Cookie: language=en-CA; path=/; expires=Tue, 22-Oct-2019 18:21:18 GMT
Set-Cookie: page_size=10; path=/; expires=Thu, 22-Oct-2015 18:21:18 GMT
Set-Cookie: SRV=app09; path=/; domain=.bibliocommons.com
Cache-control: private
Age: 1
Connection: close
PRACTICE BY YOURSELF
The easiest way of getting familiar with the concepts from this post is through a web proxy
like FIDDLER 2.
You can download it from http://www.telerik.com/fiddler.
After downloading it, install the app and start it.
You will see in FIDDLER2 all web requests captured from all open browsers.
You can get access to lots of information about web requests in FIDDLER 2 in just a few
minutes:
- requests embedded in the web page that corresponds to a web request (URL)
- request header
- response header and response data