如何使用netcat实现http get?

如何使用netcat实现http get?,http,netcat,Http,Netcat,我正在尝试使用netcat提交HTTP GET请求。但它给了我505的误差。有人知道我使用netcat有什么问题吗?谢谢 $ 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

我正在尝试使用
netcat
提交HTTP GET请求。但它给了我505的误差。有人知道我使用netcat有什么问题吗?谢谢

$ 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
$cat main.sh
#!/usr/bin/env bash

netcat-v httpbin.org 80必须使用CRLF行结尾,并且必须包含主机头

~$ printf 'GET /get HTTP/1.1\r\nHost:httpbin.org\r\n\r\n' | nc -v httpbin.org 80 
HTTP/1.1 200 OK
[…]

这里有一个更具可读性的解决方案

$ sed 's/$/\r/g' <<EOF | netcat -v httpbin.org 80
GET /get HTTP/1.1
Host:httpbin.org

EOF
$sed's/$/\r/g'