الحصول على المحتوى من نموذج نموذج HTML باستخدام TCPSocket

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

  •  15-11-2019
  •  | 
  •  

سؤال

باستخدام طريقة "يحصل" بشكل متكرر على كائن 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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top