1

I have an HttpURLConnection with a readTimeout set to 500 milliseconds for testing. Based from my understanding, readTimeout is the maximum allowable time to wait for a response. However, when I run my application, an Exception is thrown at getOutputStream. The Exception is apparently due to the readTimeout.

Why did readTimeout occur at getOutputStream? I thought getOutputStream is only for sending data and therefore, it should not wait for any response. And since it doesn't have to wait for any response, readTimeout cannot happen. Intially, I thought the readTimeout will occur at getInputStream because it is where the response is being received/ read. Can you explain how a readTimeout and connectTimeout works?

Also, when I put a timer before and after getOutputStream, the value of my timer after invoking getOutputStream is only 200+ milliseconds. My readTimeout is 500 milliseconds. Why did getOutputStream timed out earlier than the 500 milliseconds value of my readTimeout? Please note that my connectTimeout is set to 0 or infinite.

Arci
  • 6,647
  • 20
  • 70
  • 98
  • Does this help? http://stackoverflow.com/questions/4816824/httpurlconnection-post-conn-getoutputstream-throwing-exception – Dave Apr 12 '12 at 15:40
  • @Dave: Thanks! But there is no readTimeout set on the link you gave me. My question is how does readTimeout affects getOutputStream when I thought readTimeout is supposed for getInputStream. – Arci Apr 13 '12 at 01:16

0 Answers0