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拿數(shù)據(jù)的.但有時會返回{"errorCode":213,"errorMsg":"Timeout","success":"false"}
我現(xiàn)在是想如果返回Timeout ,我就執(zhí)行某些操作..該怎么做啊?
這些返回出來的都是字符啊.沒法判斷
如果是判斷api內(nèi)部超時就解析得到的結(jié)果,這個字符串是可以轉(zhuǎn)成JSON處理的,可以根據(jù)errorMsg
或者errorCode
來做判斷。
如果是判斷請求響應(yīng)超時就在catch里面判斷異常信息,會有個timeout異常的