简体   繁体   中英

How to retry the url for n number of times in HttpUrlconnection java?

I am using HTTPUrlConnection to sending request from my server. If Connection is failure i have to retry for 3 times. Currently i am using while loop to send n number of retries.

Does any one know that any default method is there in HttpUrlconnection or else Apache Httpclient provides any default method to achieve this?

You can use connectionTimeout which makes more sense for obtaining a connection rather than retries.

http://download.java.net/jdk7/archive/b123/docs/api/java/net/URLConnection.html#setConnectTimeout(int)

To answer your question, there is no api method which takes retry attempts and act accordingly. Easy way is to use the loop as you are already doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM