Why would a “java.net.ConnectException: Connection timed out” exception occur when URL is up?

后端 未结 10 1761
傲寒
傲寒 2020-11-29 18:42

I\'m getting a ConnectException: Connection timed out with some frequency from my code. The URL I am trying to hit is up. The same code works for some users,

10条回答
  •  温柔的废话
    2020-11-29 19:16

    I'd recommend raising the connection timeout time before getting the output stream, like so:

    urlConnection.setConnectTimeout(1000);
    

    Where 1000 is in milliseconds (1000 milliseconds = 1 second).

提交回复
热议问题