I'm learning some networking and am having problems with the first exercise:
I'm supposed to send a basic HTTP GET request to httpbin.org using telnet.
Here's what I typed:
$ telnet www.httpbin.org 80
Trying 23.23.171.5...
Connected to www.httpbin.org.herokudns.com.
Escape character is '^]'.
GET /ip HTTP/1.0
and here's what I'm getting:
HTTP/1.1 400 Bad Request
Server: Cowboy
Date: Tue, 09 Jan 2018 20:06:36 GMT
Content-Length: 0
What am I doing wrong?
Best Answer
The problem is using HTTP 1.0 on a server that requires HTTP 1.1 (and the
Host:
header that is a mandatory part of HTTP 1.1), probably because it is probably doing virtual hosting of multiple websites on one IP address. Or maybe it is behind an HTTP load balancer or reverse proxy that is basically doing the same thing: supporting multiple separate web server domain names behind one IP address and port.This works for me:
…and I get back…
Note that the connection stayed open and I had to escape to the
telnet>
prompt to close. I could have avoided that by adding aConnection: close
header to my request.If you try HTTP/1.1 with a
Host:
header and it still doesn't work for you, make sure your telnet client is sending CRLFs and not just carriage returns or linefeeds. Make sure you end your request with an extra CRLF after the last line.