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.