lundi 31 août 2015

Sometimes getting "java.net.connectexception connection refused" while querying geoplugin's API

I'm writing an application that queries geoplugin's IP database multiple times, and every once in a while java.net.connectexception connection refused will appear (if I'm sending 150 requests, up to 10 might get refused).
I'm sending the requests like this:

private String getContent(URL url) throws  Exception {

    HttpURLConnection http = (HttpURLConnection) url.openConnection ();
    http.connect ();

    int code = http.getResponseCode();
    if(code != 200) throw new RuntimeException("Failed to get the location. Http Status code : " + code);
    return this.getContent(http);
}

The url format is: http://ift.tt/1O3s8JV
Is there an easy way to keep resending the requests until they get accepted?




Aucun commentaire:

Enregistrer un commentaire