search

Home  >  Q&A  >  body text

php - How does java determine when the crawled data request has timed out?

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

巴扎黑巴扎黑2839 days ago468

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:04:09

    Just check whether there is a string like timeout in the row of data you get back. If there is, it will time out

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-16 13:04:09

    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

    reply
    0
  • Cancelreply