Android: connection timeout not working (connection waits forever)

后端 未结 1 1211
再見小時候
再見小時候 2020-12-30 17:40

I have an application that connects to a server. I set a timeout, disconnected the device from internet and tried to execute the post request to see if the timeout was calle

相关标签:
1条回答
  • 2020-12-30 18:18

    If you have no Internet the DNS request will fail, but you cannot control the DNS timeout. Eventually you should get an UnknownHostException, but this may take several minutes. In this case the best thing to do is to start a timer in a separate thread at the same time you make the HTTP request. If the timer goes off before the HTTP request has finished, you can abort the HTTP request.

    0 讨论(0)
提交回复
热议问题