php - java用什么方法判断爬过来的数据请求超时?
巴扎黑
巴扎黑 2017-05-16 13:02:09
0
2
398
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 ,我就执行某些操作..该怎么做啊?
这些返回出来的都是字符啊.没法判断

巴扎黑
巴扎黑

reply all (2)
我想大声告诉你

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 onerrorMsg或者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

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!