質問

TCPSocketオブジェクトで 'gets'メソッドを繰り返し使用する場合は、次の出力を受け取ります。

POST /targetPage.html HTTP/1.1
Host: 127.0.0.1:7125
...
...
...
Keep-Alive: 115
DNT: 1
Connection: keep-alive
Referer: http://127.0.0.1:7125/
Content-Type: application/x-www-form-urlencoded
Content-Length: 45
.

私が使用するならば、すべてがすべてハングする、長さ45の「コンテンツ」を手に入れるのでしょうか。私はこれを私のTCPSocketオブジェクトから入手することができますか、それとも他の何かを使う必要がありますか?

役に立ちましたか?

解決

gets reads a line, so it will block until the connection times out or it reads a newline character. You should use the read method, which reads a given number of bytes (which is very conveniently provided in the Content-Length header).

他のヒント

Include the header:

Connection: close

to the header. This will prevent the hanging before actually reading the body of the request.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top