0

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?

4

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:

$ telnet www.httpbin.org 80
Trying 23.23.171.5...
Connected to www.httpbin.org.herokudns.com.
Escape character is '^]'.
GET /ip HTTP/1.1
Host: www.httpbin.org

…and I get back…

HTTP/1.1 200 OK
Connection: keep-alive
Server: meinheld/0.6.1
Date: Tue, 09 Jan 2018 22:01:19 GMT
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
X-Processed-Time: 0.000454902648926
Content-Length: 32
Via: 1.1 vegur

{
  "origin": "[My IPv4 address redacted]"
}

^]
telnet> close
$ 

Note that the connection stayed open and I had to escape to the telnet> prompt to close. I could have avoided that by adding a Connection: 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.

  • CRLF is crucial here. I didn't need to use the User-Agent header. – pbies Oct 24 '18 at 6:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.