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

StackOverflow https://stackoverflow.com/questions/19958836

Frage

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.

War es hilfreich?

Lösung

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
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top