【问题标题】:get whole location header value of response in Jsoup在 Jsoup 中获取响应的整个位置标头值
【发布时间】:2018-10-25 09:29:30
【问题描述】:

我想从响应中获取位置标头。我正在为此使用 Jsoup。 下面是我正在使用的代码。

        Response loginFormFirst = Jsoup.connect("https://myurl.com/admin/login/auth/")
                .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0")
                .header("Accept-Language", "text/html")
                .followRedirects(false)
                .execute(); 

有了这个我可以得到 Location 标头值 - https://myurl.com/admin/auth/login/ 但这与浏览器的网络选项卡中的不同。 我希望 Location 标头值显示在浏览器的网络选项卡中。 谢谢。

【问题讨论】:

    标签: java http-headers jsoup


    【解决方案1】:

    也许如果您使用 Jsoup 并且想要检索您的网站的 html 代码,您应该检索一个包含您的网站的 HTML 代码(包括脚本或 PHP)的文档。

    获取Document的方式是:

    Document document = Jsoup.connect("https://myurl.com/admin/login/auth/")
                             .userAgent("Mozilla/5.0")
                             .get();
    

    如果你想检索解析为字符串的 HTML,你应该使用:

    String parsedHtml = Jsoup.connect("https://myurl.com/admin/login/auth/")
                             .userAgent("Mozilla/5.0")
                             .get()
                             .html();
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-02
      • 2016-07-16
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      相关资源
      最近更新 更多