Hello every reader,
as I stated before that I will explain each word in the Http request or response,starting from the first word of the Http request which is the request method.
There are eight different methods of Http requests and thy are:
OPTIONS
GET
HEAD
POST
PUT
DELETE
TRACE
CONNECT
NOTE:first take my advice and install apache (or any Http server)to your system,then come back to lesson.
OPTIONS:this method is used to request information about the allowed request methods associated with a the requested resource and supported by the server,the client recognizes those allowed methods,because they will be preceded by “Allow” header,for example let's send an OPTIONS request to localhost or any host you want,to send an Http request there many ways,let's follow this:
first open your command line and type:
telnet localhost 80
this means open a connection to the host “localhost” on the port 80(which is the Http port, here is list to common ports).
After typing this you see a message telling you that you are connected to localhost,just like this:
Trying ::1...
Connected to localhost.
Escape character is '^]'.
after this message you must type the Http request,you know that the first line is a must but the others are optional,let's write the OPTIONS request:
OPTIONS / HTTP/1.0
after typing the previous line leave a blank line by pressing enter then re-press enter again(the first enter is for leaving a blank line and the second enter is for sending the request to localhost).
If your request succeeds you will see the following response:
HTTP/1.1 200 OK
Date: Mon, 21 Feb 2011 18:22:57 GMT
Server: Apache/2.2.14 (Ubuntu)
Allow: GET,HEAD,POST,OPTIONS
Vary: Accept-Encoding
Content-Length: 0
Connection: close
Content-Type: text/html
I think you see that the Allowed methods are:
GET,HEAD,POST,OPTIONS
GET:this method is used to get the content of the requested resource such as an image,html,and many other common http mime types described by CONTENT-TYPE header,the GET request can carry more information as parameters,for example let's have the following page new.php,we will send this page a GET request with two parameters,word1 and word2:
<?php
$word1=$_GET['word1'];
$word2=$_GET['word2'];
?>
<html>
<body>
<?php
echo $word1.” “.$word2;
?>
</form>
</body>
</html>
this request looks like this:
GET /new.php?word1=hello&word2=world HTTP/1.0
the response will be:
HTTP/1.1 200 OK
Date: Mon, 21 Feb 2011 18:58:09 GMT
Server: Apache/2.2.17 (Win32) PHP/5.3.5
X-Powered-By: PHP/5.3.5
Content-Length: 43
Connection: close
Content-Type: text/html
<html>
<body>
hello world</body>
</html>
HEAD:this method is similar to GET but the response will be without the message body,(we haven't talked about the Http response yet,but each response contains a Message Body as we will see later).
This method is usually used to test hypertext links for validity(the link works or not),accessibility(you have the permission to access the requested resource or not) and recent modifications.
Let's now send a HEAD request to localhost and compare it with GET request:
HEAD / HTTP/1.0
the response will be:
HTTP/1.1 200 OK
Date: Fri, 25 Feb 2011 08:39:56 GMT
Server: Apache/2.2.14 (Ubuntu)
Last-Modified: Tue, 01 Feb 2011 08:31:24 GMT
ETag: "e041c-b1-49b345b95ef00"
Accept-Ranges: bytes
Content-Length: 177
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
now send a GET request to local host requesting / and see the response.
POST:this method is used to send data to the server with capability to carry more data than GET
with more secrecy (the sent information is enclosed inside the POST_DATA portion of the Http request whereas in GET the sent information is always sent within the Http_url).
POST can be used also to upload files to web servers by sending the file content in the POST_DATA.
Example:
you can send POST request as in the previous examples.
Examples:
this is an example of a POST request issued by a form with two text fields as the above GET request:
POST /new.php HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/msword, application/vnd.ms-powerpoint, */*
Accept-Language: ar-sa
Content-Type: application/x-www-form-urlencoded
Pragma: no-cache
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: localhost
Proxy-Connection: Keep-Alive
Content-Length: 25
word1=hello&word2=world
the response is:
HTTP/1.1 200 OK
Date: Fri, 25 Feb 2011 14:28:14 GMT
Server: Apache/2.2.17 (Win32) PHP/5.3.5
X-Powered-By: PHP/5.3.5
Content-Length: 45
Connection: close
Content-Type: text/html
<html>
<body>
hello world
</body>
</html>
PUT:this method is used to upload files to web servers in simpler way than POST requests,example of uploading a file using PUT request:
PUT /script.php HTTP/1.1
the previous example will upload the file script.php to the web server,but this method is disabled in most web servers because the attackers can exploit this method to overwrite the original files located at that server.
DELETE: we use DELETE request to delete the resource specified by the request ,the DELETE request looks like:
DELETE /file.ext HTTP/1.0
this request deletes the file file.ext from the web server,this method is disabled in most web servers
because it can be exploited by bad people to delete what they want to delete.
NOTE:you can configure your web server to redirect those requests to a specified script.
TRACE:it allows the client to see what is being received by the other end of the request chain and
use that data for testing and diagnostic information,the request chain may be:
client->proxy->server or client->server.
I mean that the other end responds to the client with the last request it receives,this enables the client to know if there is a proxy in the middle of the way between the client and server,I'm sorry but I have no real world examples.
CONNECT:This specification reserves the method name CONNECT for use with a
proxy that can dynamically switch to being a tunnel (e.g. SSL tunneling).
those are all Http request methods that can be used ,we will continue with the hyper text transfer protocol at next lesson,goodbye.