Friday, January 27, 2012

Basic introduction of HTTP Protocol




Please visit my new Web Site WWW.Codedisplay.com



At first what is Protocol? Protocol means a way of communication between two or more parties. To connect two parties like client and server at first we need to establish a connection between them and after that we need to start communication in such a way so that anyone can understand each other. To establish a connection we need a special protocol named Transmission Control Protocol/Internet Protocol (TCP/IP). Which has become the industry-standard method of interconnecting hosts, networks, and the Internet. Now think that connection between client and server has been established. Now we need to set a way of communication like messages, so that they can understand both. This message format standard is HTTP which defines how client will send a request to the server and how the server will response. HTTP stands for "Hypertext Transfer Protocol". In case of Web Browser and Web Server, The Web Browser is HTTP Client and the Web Server is HTTP Server.

More precisely the definition of HTTP protocol is a protocol designed to allow the transfer of Hypertext Markup Language (HTML) documents.


An HTTP transaction is divided into four steps:
1. The browser opens a connection by using TCP/IP.
2. The browser sends a request to the server --> The request is a message and the message format follows HTTP Protocol.
3. The server sends a response to the browser --> The response also a message and the message format follows HTTP Protocol.
4. The connection is closed.

So what we understand? We understand on the Internet, HTTP communication generally takes place over TCP connections. The default port is 80 but other ports can be used..

HTTP Protocol is Connection less:
The protocol is called connection less because An HTTP client opens a connection and sends a request message to the HTTP server, After that the server then returns a response message containing the resource which was requested. After delivering the response, the server closes the connection unlike other protocol likes FTP, which makes HTTP Protocol is a connection less protocol.

HTTP protocol is State less:
When the server responded of client request, the connection between client and server is closed means forgotten. There is no "Tracking System" between client and server. The HTTP server takes every request as a new request means never maintain any connection information between transactions. But there are some ways to maintain states between client and server which i have already described in my previous article: "Passing data/parameters/values from one aspx page to another aspx page".

HTTP Message Example:
Request:
GET /path/file.html HTTP/1.0
From: shawpnendu@gmail.com
User-Agent: HTTPTool/1.0
[blank line here]

Response:
HTTP/4.0 200 OK
Content-Type: text/html
Content-Length: 2000

<html>
<body>
<h1>HELLO WORLD</h1>
(more file contents)
  .
  .
  .
</body>
</html>
To know more about Content-Type CLICK HERE.

HTTP Methods:
The most commonly used methods are GET and POST. To know more about Get and POST method click "Difference between HTTP GET and POST methods".

Other Common Methods are:
HEAD: A HEAD request is just like a GET request, except it asks the server to return the response headers only, and not the actual resource (i.e. no message body). This is useful to check characteristics of a resource without actually downloading it which saves bandwidth. Mostly wide use of this method is crawler.

PUT: Mostly used for uploading files.

Common HTTP Response Status Code:
Successful (2xx):
200: OK
201: Created
202: Accepted
203: Non-Authoritative Information
204: No Content -205 Reset Content
206: Partial Content

Redirection (3xx):
300: Multiple Choices
301: Moved Permanently
302: Moved Temporarily
303: See Other
304: Not Modified
305: Use Proxy


Client error (4xx):
400: Bad Request
401: Unauthorized
402: Payment Required
403: Forbidden
404: Not Found
405: Method Not Allowed
406: Not Acceptable
407: Proxy Authentication Required
408: Request Timeout
409: Conflict
410: Gone
411: Length Required
412: Precondition Failed
413: Request Entity Too Large
414: Request-URI Too Long
415: Unsupported Media Type


Server error (5xx):
500: Internal Server Error
502: Bad Gateway
503: Service Unavailable
504: Gateway Timeout
505: HTTP Version Not Supported

Monday, January 16, 2012

Basic difference on GET and Post HTTP methods




Please visit my new Web Site WWW.Codedisplay.com



Might be this the first interview question by the viva board. Which is very basic and you have to explain clearly. That's why i am trying to write the post "Basic difference between GET and POST method". Basically both method is used for submitting data into server. Read the differences from below:

Post Mechanism:
1. GET request is sent via URL.
2. Post request is sent via HTTP request body or you can say internally.

GET POST Difference
Figure: Get Method Indication


Sample Code:
<html>
<body>
<Form method="GET" Action="http://search.yahoo.com/bin/search">
Name: 
<input type="Text" name="Name" />
<input type="submit" value="Check" />
</Form>
</body>
</html>
</pre>
</pre>


Form Default Method:
1. GET request is the default method.
2. You have to specify POST method within form tag like <Form method="POST".......

Security:
1. Since GET request is sent via URL, so that we can not use this method for sensitive data data.
2. Since Post request encapsulated name pair values in HTTP request body, so that we can submit sensitive data through POST method.

Length:
1. GET request has a limitation on its length. The good practice is never allow more than 255 characters.
2. POST request has no major limitation. Read discussion part later of this article.

Caching or Bookmarking:
1. GET request will be better for caching and bookmarking.
2. POST request has not.

SEO:
1. GET request is SEO friendly.
2. POST request has not.

Data Type:
1. GET request always submitted data as TEXT.
2. POST request has no restriction.

Best Example:
1. SEARCH will be the best example for GET request.
2. LOGIN will be the best example for POST request.

HTTP Request Message Format:
GET:
GET /path/file.html?SearchText=Interview_Question HTTP/1.0
From: shawpnendu@gmail.com
User-Agent: HTTPTool/1.0
[blank line here]

POST:
POST /path/script.cgi HTTP/1.0
From: shawpnendu@gmail.com
User-Agent: HTTPTool/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 8

Code=132

Some comments on the limit on QueryString / GET / URL parameters Length:
1. 255 bytes length is fine, because some older browser may not support more than that.
2. Opera supports ~4050 characters.
3. IE 4.0+ supports exactly 2083 characters.
4. Netscape 3 -> 4.78 support up to 8192 characters.
5. There is no limit on the number of parameters on a URL, but only on the length.
6. The number of characters will be significantly reduced if you have special characters like spaces that need to be URLEncoded (e.g. converted to the '%20').
7. If you are closer to the length limit better use POST method instead of GET method.

Sunday, January 8, 2012

Short description on MIME type




Please visit my new Web Site WWW.Codedisplay.com



MIME = Multi-purpose Internet Mail Extensions.

This article will explain "What is ENC MIME type". Its a commonly used basic viva/written interview question. MIME type is a standard way of defining file types between HTTP Client and HTTP Server. Without a standard MIME type both client and server can not understand what type of file client received since a file has many extensions like HTML and HTM. To overcome this problem MIME type takes place.

Usually MIME type consists of two parts. One is type and another one is subtype which is separated by a front slash (/). For example the MIME type of Microsoft Excel file is application and the subtype is vnd.ms-excel. So the complete MIME type will be application/vnd.ms-excel. Hope you can understand now.

The web server determine correct MIME type by using a Content-type: header when it responds to a HTTP client request like web browser's.



The following table shows some common MIME types:

text/html: HTML Web Page.
application/octet-stream: To Download a file.
application/msword: For Microsoft Word Document.
application/vnd.ms-excel: For Microsoft Word Excel
application/xml: For XML file
application/zip: For ZIP file
image/bmp: For BMP image
image/png: For PNG type image
image/jpeg: For JPEG file
audio/mpeg: For MPEG type

An example of using MIME type in ASP.Net C#... CLICK HERE

Some other MIME types:

File type MIME type
ai application/postscript
aif audio/x-aiff
aifc audio/x-aiff
aiff audio/x-aiff
asc text/plain
atom application/atom+xml
au audio/basic
avi video/x-msvideo
bcpio application/x-bcpio
bin application/octet-stream
bmp image/bmp
cdf application/x-netcdf
cgm image/cgm
class application/octet-stream
cpio application/x-cpio
cpt application/mac-compactpro
csh application/x-csh
css text/css
dcr application/x-director
dif video/x-dv
dir application/x-director
djv image/vnd.djvu
djvu image/vnd.djvu
dll application/octet-stream
dmg application/octet-stream
dms application/octet-stream
doc application/msword
dtd application/xml-dtd
dv video/x-dv
dvi application/x-dvi
dxr application/x-director
eps application/postscript
etx text/x-setext
exe application/octet-stream
ez application/andrew-inset
gif image/gif
gram application/srgs
grxml application/srgs+xml
gtar application/x-gtar
hdf application/x-hdf
hqx application/mac-binhex40
htm text/html
html text/html
ice x-conference/x-cooltalk
ico image/x-icon
ics text/calendar
ief image/ief
ifb text/calendar
iges model/iges
igs model/iges
jnlp application/x-java-jnlp-file
jp2 image/jp2
jpe image/jpeg
jpeg image/jpeg
jpg image/jpeg
js application/x-javascript
kar audio/midi
latex application/x-latex
lha application/octet-stream
lzh application/octet-stream
m3u audio/x-mpegurl
m4a audio/mp4a-latm
m4b audio/mp4a-latm
m4p audio/mp4a-latm
m4u video/vnd.mpegurl
m4v video/x-m4v
mac image/x-macpaint
man application/x-troff-man
mathml application/mathml+xml
me application/x-troff-me
mesh model/mesh
mid audio/midi
midi audio/midi
mif application/vnd.mif
mov video/quicktime
movie video/x-sgi-movie
mp2 audio/mpeg
mp3 audio/mpeg
mp4 video/mp4
mpe video/mpeg
mpeg video/mpeg
mpg video/mpeg
mpga audio/mpeg
ms application/x-troff-ms
msh model/mesh
mxu video/vnd.mpegurl
nc application/x-netcdf
oda application/oda
ogg application/ogg
pbm image/x-portable-bitmap
pct image/pict
pdb chemical/x-pdb
pdf application/pdf
pgm image/x-portable-graymap
pgn application/x-chess-pgn
pic image/pict
pict image/pict
png image/png
pnm image/x-portable-anymap
pnt image/x-macpaint
pntg image/x-macpaint
ppm image/x-portable-pixmap
ppt application/vnd.ms-powerpoint
ps application/postscript
qt video/quicktime
qti image/x-quicktime
qtif image/x-quicktime
ra audio/x-pn-realaudio
ram audio/x-pn-realaudio
ras image/x-cmu-raster
rdf application/rdf+xml
rgb image/x-rgb
rm application/vnd.rn-realmedia
roff application/x-troff
rtf text/rtf
rtx text/richtext
sgm text/sgml
sgml text/sgml
sh application/x-sh
shar application/x-shar
silo model/mesh
sit application/x-stuffit
skd application/x-koan
skm application/x-koan
skp application/x-koan
skt application/x-koan
smi application/smil
smil application/smil
snd audio/basic
so application/octet-stream
spl application/x-futuresplash
src application/x-wais-source
sv4cpio application/x-sv4cpio
sv4crc application/x-sv4crc
svg image/svg+xml
swf application/x-shockwave-flash
t application/x-troff
tar application/x-tar
tcl application/x-tcl
tex application/x-tex
texi application/x-texinfo
texinfo application/x-texinfo
tif image/tiff
tiff image/tiff
tr application/x-troff
tsv text/tab-separated-values
txt text/plain
ustar application/x-ustar
vcd application/x-cdlink
vrml model/vrml
vxml application/voicexml+xml
wav audio/x-wav
wbmp image/vnd.wap.wbmp
wbmxl application/vnd.wap.wbxml
wml text/vnd.wap.wml
wmlc application/vnd.wap.wmlc
wmls text/vnd.wap.wmlscript
wmlsc application/vnd.wap.wmlscriptc
wrl model/vrml
xbm image/x-xbitmap
xht application/xhtml+xml
xhtml application/xhtml+xml
xls application/vnd.ms-excel
xml application/xml
xpm image/x-xpixmap
xsl application/xml
xslt application/xslt+xml
xul application/vnd.mozilla.xul+xml
xwd image/x-xwindowdump
xyz chemical/x-xyz
zip application/zip
Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash