HTTP/1.1标头的新行定义 [英] New Line definition for HTTP/1.1 headers
问题描述
我有一个发出HTTP POST请求的嵌入式系统,但是我知道标题必须具有格式.
I have an embedded system that makes a HTTP POST request, however I know that the headers must have a format.
在这种情况下,我有以下要求:
In this case I have this request:
POST / HTTP/1.1\n
Host: 192.168.1.15\n
Connection: close\n
Content-Length: 44\n
Content-Type: application/json\n
\n
{\n
"command": "snapPicture",\n
"selfTimer": 0\n
}
我希望在发送此请求时避免发生任何错误.
I want to avoid any kind of error while I send this request.
-
严格来说,使用
\n
来告诉new line
是正确的还是应该是\r\n
?
Strictly talking, is it correct use
\n
to tellnew line
or should be\r\n
?
关于此请求格式的任何建议吗?
Any suggestion about this request format?
感谢您的帮助.
推荐答案
您必须使用\r\n
分隔标题,并将正文与标题部分分隔开.请参阅 RFC 7230(超文本传输协议(HTTP/1.1):消息语法和路由),第3节.邮件格式:
You must use \r\n
to separate headers, also to separate the body from the header section. See RFC 7230 (Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing), section 3. Message Format:
HTTP-message = start-line
*( header-field CRLF )
CRLF
[ message-body ]
CRLF
是\r\n
.
其余请求是否有效(尤其是正文)取决于您将请求发送到的服务器.
Whether the rest of the request is valid, especially the body, depends on the server you send it to.
这篇关于HTTP/1.1标头的新行定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!