rubycoloredglasses


I'm Jason, a web application developer in East Tennessee.


HTTP Port and Request Methods

HTTP Ports

A web browser by default will make a request to an HTTP server on port 80, the standard HTTP server port, however it's possible for web servers to use a different port in special circumstances. To specify an alternative port in the address for the request, simply add a colon and the number after the domain. For instance many hosting companies use a system known as cPanel to manage their hosting accounts on a web server. Since the web server runs on port 80, the cPanel administrative interface runs on port 2082 like so: http://www.redconfetti.com:2082/

Standard GET and POST Requests

The most common HTTP method used to make a request of a web server is the 'GET' method, which simply tells the server to provide the contents of a specific resource based on the URL. Upon receiving the request, the server sends back a status line, such as "HTTP/1.1 200 OK" (indicating a successful request), along with the body of the response which is either the HTML webpage being requested, or an error message.

For example, here is the GET request sent to a server after the browser has been told to go to http://www.example.com/index.html

GET /index.html HTTP/1.1
Host: www.example.com

The server might then respond with these headers:

HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Etag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8

...and thereafter include the 438 bytes of HTML coding for the index web page in the body of the response.

The contents of an HTTP request are not seen in the web browser when requesting a web page, and just the same the 'header' information of the HTTP response provided by the server are not seen in the web browser either. It is only the body of the response which is either rendered in the browser window (such as an HTML web page), or displayed directly (such as images).

Sometimes a GET request includes additional information used by the resource. For instance a webpage address such as http://www.redconfetti.com/index.php?page=about&style=black would result in a request such as:

GET /index.php?page=about&style=black HTTP/1.1
Host: www.example.com

This type of request allows you to see the information being provided to the server in the URL for the page/resource. This method is recommended for webpages which provide different information based on the additional parameters included in the request, but not for scripts/pages which create, update, or delete resources on the server as the URL can be bookmarked and re-used, leading to accidental and unwanted modifications.

The second most common HTTP method used with requests to web servers is the 'POST' method. A POST request is the type typically used when a web form is submitted to the server. A web form can either submit information via GET (like shown above) or via a POST request. A POST request includes information in a certain format in addition to the path of the resource.

This type of request cannot be accidentally re-submitted to the server, and in fact your browser will specifically ask you if you wish to re-submit the request when you choose to 'Refresh' a page that was loaded via a POST request.

A POST request for an email form on a website may look like this:

POST /contact/send-email.php HTTP/1.1
Host: www.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 46

name=John%20Smith&email=john.smith@mailinator.com&message=Hello,How%20are%20you!

Other HTTP Methods

HTTP defines nine methods/request types indicating the desired action to be performed on the resource (webpage, image, or other file) being requested. These methods are: HEAD, GET, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, and PATCH.

Most people think of HTTP as a simple read-only medium where a browser makes a request and receives information, and the only method available to publish or remove content from a website is via FTP. Tim Berners-Lee, the inventor of the World Wide Web, originally designed the first browser called "WorldWideWeb" as a read/write browser; meaning you could not only browse and read content, but create and edit content too. The majority of websites today only operate through GET requests for the majority of pages, and sometimes use POST for web form submissions, but do not utilize the other HTTP requests types. These other request methods were intended to allow web servers to act like full services which not only provide options to 'GET' resources, but also to create new resources using the 'PUT' request type, or delete resources using the 'DELETE' request type.

The PUT method is similar to POST, as it provides data with the request separate of the path of the resource being requested. The DELETE method is much like GET, but is intended for requests to delete certain resources.

More detail on the HTTP methods is available W3.org Definitions page.

[previous]
[next]