W
W
wera77772015-11-12 05:50:47
Java
wera7777, 2015-11-12 05:50:47

How to contact another url if the main one suddenly became unavailable?

There is a project that uses libraries org.apache.http.*;
. But according to the examples, I can only work with 1 (url) service (API), but what if it does not respond?
How to make a robot with a list of url addresses, so that if the first one does not respond within 3 seconds, send a request to another url and so on until the end of the list?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2015-11-12
@GavriKos

There are no automatic means in your library for this. Implement by hand. Actually, you have already written the algorithm, it remains only to implement it beautifully. Write your own class, pass a list of all URLs as a parameter. In it, outside - the GetResponse method, well, two callbacks - OnResponse, OnError, For example ...

A
aol-nnov, 2015-11-12
@aol-nnov

on good, it is necessary to solve the architecture of the backend. failovers, pp dns and more :)

C
Chvalov, 2015-11-12
@Chvalov

It seems like the OkHttp library can work with several addresses, more precisely, if one does not answer, then it knocks on the other.
I didn’t use it myself because I don’t work with the web, who tried it, write in the comments if this is so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question