Reputation: 13683
I am trying to use netcat
to submit an HTTP GET
request. But it gives me the 505 error.
Does anybody know what is wrong with my use of netcat
?
Thanks.
$ cat main.sh
#!/usr/bin/env bash
netcat -v httpbin.org 80 <<EOF
GET /get HTTP/1.1
EOF
$ ./main.sh
httpbin.org [23.23.171.5] 80 (http) open
HTTP/1.1 505 HTTP Version Not Supported
Connection: close
Server: Cowboy
Date: Fri, 09 Feb 2018 00:26:37 GMT
Content-Length: 0
Upvotes: 5
Views: 8628
Reputation: 13683
Here is a more readable solution.
$ sed 's/$/\r/g' <<EOF | netcat -v httpbin.org 80
GET /get HTTP/1.1
Host:httpbin.org
EOF
Upvotes: 3
Reputation: 177634
You must use CRLF line endings, and you must include a Host header.
~$ printf 'GET /get HTTP/1.1\r\nHost:httpbin.org\r\n\r\n' | nc -v httpbin.org 80
HTTP/1.1 200 OK
[…]
Upvotes: 10