Получение содержимого от HTML-формы Post с помощью TCPSocket

StackOverflow https://stackoverflow.com/questions/6050099

  •  15-11-2019
  •  | 
  •  

Вопрос

Использование метода «Получает» многократно на объекте TCPSocket, я получаю следующий выход

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
.

Если я использую .gets снова все зависает, как бы я получил это «контент» длины 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