Ottenere il contenuto da un post del modulo HTML utilizzando TCPSocket
Domanda
Utilizzando il metodo 'Get' ripetutamente su un oggetto TCPSocket, ricevo la seguente output
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
.
Se utilizzo. Everys di nuovo tutto si blocca, come avrei ottenuto questo "contenuto" di lunghezza 45?Posso ottenere questo dal mio oggetto TCPSocket o devo usare qualcos'altro?
Soluzione
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).
Altri suggerimenti
Include the header:
Connection: close
to the header. This will prevent the hanging before actually reading the body of the request.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow