Search code examples
javaandroidjsouphttp-status-code-413

Jsoup, HTTPClient, HttpURLConnection. How to get a response html, if the server always returns a 413 error code


When sending a GET request to http://blahblahblah.com/site/Login/?domain=blahblahblah.com&request=[request string] server always response 413 error. In browser this request show html page with javascript redirect. But in Jsoup when get this URL throwed exception. I think this is to prevent automated login.I want to get responsed html width Jsoup.

try{
Response response = Jsoup.connect("http://blahblahblah.com/site/Login/?domain=blahblahblah.com&request=abc123").method(Method.GET).execute();
}
catch (HttpStatusException e) {
//? What i must write here to get response
}

In C#/.Net HttpWebRequest Exception object contain Response and I can extract html data from it. How to do it in java / android?

Sorry for my English.


Solution

  • You can use:

    try{
            Connection response = Jsoup.connect("http://blahblahblah.com/site/Login/?domain=blahblahblah.com&request=abc123").method(Method.GET);
            response.ignoreHttpErrors(false);
            org.jsoup.Connection.Response r = response.execute();
        }
            catch (HttpStatusException e) {
    //not throwed
        }