Unbound
Unbound

Reputation: 345

How to make a request with telnet?

Here is what the problem, using the livehttp header addon of firefox I see the header of the site is GET / HTTP/1.1. Now when I telnet from the command line telnet www.stackoverflow.com 80 and use the same exact header I get this response

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Hostname</h2>
<hr><p>HTTP Error 400. The request hostname is invalid.</p>
</BODY></HTML>

I used the same exact request.So why is the response different?

Upvotes: 0

Views: 1727

Answers (1)

Quentin
Quentin

Reputation: 943998

You didn't use the same request. This is the request that my browser made to Stackoverflow:

GET / HTTP/1.1
Host: stackoverflow.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
DNT: 1
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: REDACTED! REDACTED!

The Host header is essential for most websites these days (since so many use Virtual Name Hosting to allow multiple websites (distinguished via the hostname) to be hosted on a single ip address.

Upvotes: 3

Related Questions