Obtenir le contenu d'un message de formulaire HTML à l'aide de TCPSocket
Question
Utilisation de la méthode 'Obtient' à plusieurs reprises sur un objet TCPSocket, je reçois la sortie suivante
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
Si j'utilise à nouveau .GET à nouveau, tout est suspendu, comment puis-je obtenir ce "contenu" de la longueur 45?Puis-je obtenir cela de mon objet tcpsocket ou dois-je utiliser autre chose?
La solution
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).
Autres conseils
Include the header:
Connection: close
to the header. This will prevent the hanging before actually reading the body of the request.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow