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(); }
我是用new url 的方式来爬别人的api拿数据的.但有时会返回{"errorCode":213,"errorMsg":"Timeout","success":"false"}
我现在是想如果返回Timeout ,我就执行某些操作..该怎么做啊?
这些返回出来的都是字符啊.没法判断
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