php - How does java determine when the crawled data request has timed out?
巴扎黑
巴扎黑 2017-05-16 13:02:09
0
2
466
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

巴扎黑
巴扎黑

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 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template