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

后端 未结 10 1759
傲寒
傲寒 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 18:55

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

    Because the URLConnection (HttpURLConnection/HttpsURLConnection) is erratic. You can read about this here and here. Our solution were two things:

    a) set the ContentLength via setFixedLengthStreamingMode

    b) catch any TimeoutException and retry if it failed.

提交回复
热议问题