Yayahii
Yayahii

Reputation: 43

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?

Upvotes: 1

Views: 2161

Answers (1)

Alkis Kalogeris
Alkis Kalogeris

Reputation: 17745

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.

Upvotes: 5

Related Questions