【问题标题】:Jsoup, HTTPClient, HttpURLConnection. How to get a response html, if the server always returns a 413 error codeJsoup、HTTPClient、HttpURLConnection。如果服务器总是返回 413 错误代码,如何获取响应 html
【发布时间】:2013-11-13 16:15:09
【问题描述】:

当向 http://blahblahblah.com/site/Login/?domain=blahblahblah.com&request=[request string] 发送 GET 请求时,服务器总是响应 413 错误。在浏览器中,此请求显示带有 javascript 重定向的 html 页面。但是在 Jsoup 中获取这个 URL 的时候会抛出异常。我认为这是为了防止自动登录。我想得到响应的 html 宽度 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
}

在 C#/.Net HttpWebRequest 异常对象中包含响应,我可以从中提取 html 数据。在java/android中怎么做?

对不起我的英语。

【问题讨论】:

    标签: java android jsoup http-status-code-413


    【解决方案1】:

    你可以使用:

    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
        }
    

    【讨论】:

    • 我宁愿添加条件(仅以下 2 行)来接受额外的代码,而不是像代码 200 那样威胁所有内容。重定向等呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 2014-03-14
    • 2018-02-13
    相关资源
    最近更新 更多