Friday, May 24, 2013

What is really below a web application ? from Olivet University

Many times I am also greatly wondering, what is really behind a web application, behind a browser ?

I did a little dive into.

In web application layer, we can open an url as a resource just like open a file.

If written in python, it would be like:

import urllib,urllib2

url = "~~~~"
reply = json.load(urllib2.urlopen(url).read())
print reply['~']

....
If you want to scan a page, or make a crawler, you can simply add more code to above to achieve that.

If we move down into protocol layer, the most used protocol is HTTP.

If written in python , it would be like:

import httplib

path = '~~~'
connection = httplib.HTTPConnection(' some url ' )
connection.request('GET',path)
reply = json.load(connection.getresponse().read())
print ....

Other protocol applies too like FTP ... ,  instead of typing the source for many times, the protocol layer set up firstly a connection, and once it binds , we can just use it just like a local file.

If we continue move down, we can set up connection to any port of a remote machine, we called socket.

If written in python, it would be like:

import socket
sock = socket.socket()
sock.sendall('GET / ~~~~
                    '&parameter =~~
                    'Host:  ~~'
                    'User-Agent: ~~'
                    'Connection:  '
reply = sock.recv(port #)

if we print this reply , it can be very raw like:

HTTP/1.1 200 OK
Content- Type ~~~

 if you connection to normal HTTP socket port 80

OIT


No comments:

Post a Comment