HTTP请求至少需要什么? [英] What, at the bare minimum, is required for an HTTP request?
本文介绍了HTTP请求至少需要什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 netcat
向我的本地服务器发出GET命令,执行以下操作:
I'm trying to issue a GET command to my local server using netcat
by doing the following:
echo -e "GET / HTTP/1.1\nHost: localhost" | nc localhost 80
不幸的是,我收到 HTTP / 1.1 400 Bad Request
对此的回应。 HTTP请求至少需要什么?
Unfortunately, I get a HTTP/1.1 400 Bad Request
response for this. What, at the very minimum, is required for a HTTP request?
推荐答案
它必须使用CRLF行结尾,并且必须以 \\\\ nn结尾\\ r \\ n
,即一个空行。这就是我使用的:
It must use CRLF line endings, and it must end in \r\n\r\n
, i.e. a blank line. This is what I use:
printf 'GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n' |
nc www.example.com 80
此外,我更喜欢 printf
over echo
,我添加了一个额外的标头让服务器关闭连接,但不需要那些。
Additionally, I prefer printf
over echo
, and I add an extra header to have the server close the connection, but those aren’t needed.
这篇关于HTTP请求至少需要什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文