Q:

Why can't I get netcat talking to my Rails server?

I have a Thin server running locally, serving a Rails app. Following an example in the netcat man page, I'm trying to use nc to talk to my server:
echo -n "GET / HTTP/1.1\r\n\r\n" | nc 0.0.0.0 3000

But I get a 400 response:
HTTP/1.1 400 Bad Request
Content-Type: text/plain
Connection: close
Server: thin 1.6.1 codename Death Proof

What am I missing?

A:

HTTP 1.1 requires providing a Host: header. You also need to add the -e flag to the echo command to escape character sequences, so
echo -en "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n" | nc 0.0.0.0 3000

would work, or alternatively you could use HTTP 1.0 which does not require the Host: header, so
echo -en "GET / HTTP/1.0\r\n\r\n" | nc 0.0.0.0 3000

