HTTP 请求至少需要什么? [英] What, at the bare minimum, is required for an HTTP request?

查看:26
本文介绍了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
Host: 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 行尾,并且必须以 结尾,即一个空行.这是我使用的:

It must use CRLF line endings, and it must end in , i.e. a blank line. This is what I use:

printf 'GET / HTTP/1.1
Host: www.example.com
Connection: close

' |
  nc www.example.com 80

此外,我更喜欢 printf 而不是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆