الحصول على المحتوى من نموذج نموذج HTML باستخدام TCPSocket
سؤال
باستخدام طريقة "يحصل" بشكل متكرر على كائن TCPSocket، أتلقى الإخراج التالي giveacodicetagpre.
إذا كنت أستخدم. أجسته مرة أخرى، كل شيء توقف، كيف يمكنني الحصول على هذا "محتوى" طول 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.
لا تنتمي إلى StackOverflow