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 (つまり、10 進数の ASCII 文字 13 と 10、または Python 文字列の "\015\012") である必要があり、最初の行の後に任意の数の追加ヘッダーが続き、その後に空のヘッダーが続きます。ライン。厳密には必須ではありませんが、仮想ホストを支援するために常に Host: ヘッダーを提供する必要があります。多くのウェブサイトはこれなしでは機能しません。GET 動詞の後の URI 部分は絶対部分でなければならないため、スラッシュで始まることに注意してください。

于 2012-09-30T13:48:30.830 に答える