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

后端 未结 10 1665
傲寒
傲寒 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:13

    There is a possibility that your IP/host are blocked by the remote host, especially if it thinks you are hitting it too hard.

    0 讨论(0)
  • 2020-11-29 19:14

    The error message says it all: your connection timed out. This means your request did not get a response within some (default) timeframe. The reasons that no response was received is likely to be one of:

    a) The IP/domain or port is incorrect

    b) The IP/domain or port (i.e service) is down

    c) The IP/domain is taking longer than your default timeout to respond

    d) You have a firewall that is blocking requests or responses on whatever port you are using

    e) You have a firewall that is blocking requests to that particular host

    f) Your internet access is down

    g) Your live-server is down i.e in case of "rest-API call".

    Note that firewalls and port or IP blocking may be in place by your ISP

    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2020-11-29 19:16

    I solved my problem with:

    System.setProperty("https.proxyHost", "myProxy");
    System.setProperty("https.proxyPort", "80");
    

    or http.proxyHost...

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