简体   繁体   中英

JSOUP 503 StatusCode Error

I have the code below:

Connection.Response response = null; 
response = Jsoup.connect(URL1).ignoreContentType(true).timeout(10000).execute();
int statusCode = response.statusCode(); 
System.out.println(statusCode);

if (statusCode ==200){
     //do something
     } 

else {
    //do something
     }

The problem is I'm working with a server that often reports back 503s. When the status is 200, everything works fine. The statusCode is printed to the screen & the code below the if statement is executed. However, if the statusCode is 503, the statusCode is not printed to the screen & the else statement is not preformed at all... what am I doing wrong?

Try this

response = Jsoup.connect(URL1).ignoreContentType(true).ignoreHttpErrors(true).timeout(10000).execute();

From the javadoc

ignoreHttpErrors(boolean ignoreHttpErrors) 
Configures the request to ignore HTTP errors in the response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM