0

I'm trying to exchange HTTP messages between a client and a server. The request contains HTTP/1.0, when I place this in the beginning of the request, it works fine.

client_socket.send("HTTP/1.0 400 Bad Request")

But When I place it at the end, it doesn't received on the other side and the program halts.

client_socket.send("GET 1.txt HTTP/1.0")

When I add an extra space to the request between HTTP and /1.0

client_socket.send("GET 1.txt HTTP/ 1.0")

It works fine and I receive the contents of the requested file.

I thinks the problem is with the forward slash, I want to omit it in order to make my client connect to another given server written in another language.

4

1 回答 1

2

HTTP 1.0 请求至少具有以下格式:

GET /1.txt HTTP/1.0<CRLF>
Host: the.server.com<CRLF>
<CRLF>

也就是说,所有行结尾都应该是 CR+LF(即 ASCII 字符 13 和 10 十进制,或 Python 字符串中的“\015\012”),并且在第一行之后是任意数量的附加标题,然后是一个空线。虽然不是严格要求,但您应该始终提供 Host: 标头以帮助虚拟主机;没有这个,许多网站都无法运行。请注意,GET 动词之后的 URI 部分必须是绝对的,因此以斜杠开头。

于 2012-09-30T13:48:30.830 回答