0

When we make a request a page from a server, the request by default goes to port 80 on the server that is the http server. Why do we then type http before the path of a resource. If the request is going to a http server it must be a http request.

2
  • 1
    Think about it: can you run both an FTP service and an HTTP service on the same server? Yes. Can a browser speak to multiple protocols? Also yes. Therefore, we need to specify which protocol to use, and the prefix of the URL identifies that. Mar 19, 2014 at 21:14
  • 2
    This is off topic here. This is a basic networking question. You make several assumptions that you have not examined, including that a http server only does one thing, and that http is always port 80. Server != Service. Services respond to ports. Servers run Services.
    – schroeder
    Mar 19, 2014 at 23:20

4 Answers 4

7

You got that the other way round. If you type http://, then the request goes to port 80 unless overridden (e.g. http://www.yourserver.blah:8080/...).

But if for example you typed https://..., then the request would go - again, unless overridden - to port 443/tcp and would even "speak" a different "dialect". The same goes for ftp:// and port 21, if the browser understands the FTP protocol (as most do).

Most browsers do consider the lack of a http:// qualifier in a Web address as meaning "this goes to HTTP port 80/tcp", and they automatically add the http:// for you. Otherwise, you have to specify, and the port chosen will follow the specification.

2

To better understand how a URI (URL) works, you should refer to the RFC 3986

The generic URI syntax consists of a hierarchical sequence of
   components referred to as the scheme, authority, path, query, and
   fragment.

The following are two example URIs and their component parts:

         foo://example.com:8042/over/there?name=ferret#nose
         \_/   \______________/\_________/ \_________/ \__/
          |           |            |            |        |
       scheme     authority       path        query   fragment
          |   _____________________|__
         / \ /                        \
         urn:example:animal:ferret:nose

It is also useful not to think of the "server" as a box, but as "service" running on a specific port. When the client makes the request, it doesn't know who will be receiving it. While the standard is 80, there is no reason that cannot be an SSH server. Imagine a scenario where someone is behind a firewall and wants to SSH to their home box, if they run the SSH server on port 80, they may be able to get past basic firewall rules that allow you to open a connection to port 80. There are defaults, but they are not requirements.

Also keep in mind, that the usage of a URL is for the user. When you specify http:// it tells the user to create an HTTP request to the address. Your request of the browser for http://www.example.com is then translated to the HTTP protocol. This article gives a pretty good description:

For example, the browser translated the URL http://www.test101.com/doc/index.html into the following request message:

GET /docs/index.html HTTP/1.1
Host: www.test101.com
Accept: image/gif, image/jpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
(blank line)
0

You need to tell the browser what protocol you want it to speak to the server. Most browsers support multiple protocols in the main navigation area, such as https and ftp, which use port 443 and 21/22 respectively.

0

Since nobody has mentioned it so far, it is not required to specify http:// or https://

Example: Google recommends using just // instead of http:// or https:// as it will default to whatever is being used on the page.

Example from Google code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .