try{
URL url = new URL("https://api.XXXX.com/?_="+new Date().getTime());
urlConnection = url.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(urlConnection.getInputStream()));
while((current = in.readLine()) != null)
{
urlString += current;
}
return urlString;
}catch(IOException e){
e.printStackTrace();
}
I use new url to crawl other people's APIs to get data. But sometimes it returns {"errorCode":213,"errorMsg":"Timeout","success":"false"}
Now I want to perform certain operations if Timeout is returned.. What should I do?
These returned characters are all characters. There is no way to judge
Just check whether there is a string like timeout in the row of data you get back. If there is, it will time out
If it is the result of parsing to determine the internal timeout of the API, this string can be converted into JSON for processing, and the judgment can be made based on
errorMsg
或者errorCode
.If it is judged that the request response has timed out, judge the exception information in the catch, there will be a timeout exception