JSoup.connect与某些请求有403错误

时间:2016-06-21 21:07:52

标签: java jsoup http-status-code-403

我尝试通过此页面的Jsoup.connect获取HTML源代码:https://bitskins.com/?market_hash_name=SSG+08+%7C+DARK+WATER+%28Field-Tested%29&is_stattrak=0&has_stickers=0&sort_by=bumped_at&order=desc

但是,我有错误:Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403, URL=https://bitskins.com/?market_hash_name=SSG+08+%7C+DARK+WATER+%28Field-Tested%29&is_stattrak=0&has_stickers=0&sort_by=bumped_at&order=desc

我的代码是:

Document doc = Jsoup.connect("https://bitskins.com/?market_hash_name=SSG+08+%7C+DARK+WATER+%28Field-Tested%29&is_stattrak=0&has_stickers=0&sort_by=bumped_at&order=desc")
            .data(":authority", "bitskins.com")
            .data(":method", "GET")
            .data(":path", "/?market_hash_name=SSG+08+%7C+DARK+WATER+%28Field-Tested%29&is_stattrak=0&has_stickers=0&sort_by=bumped_at&order=desc")
            .data(":scheme", "https")
            .data("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
            .data("accept-encoding", "gzip, deflate, sdch, br")
            .data("accept-language:", "ru,en-US;q=0.8,en;q=0.6")
            .data("cache-control", "max-age=0")
            .data("cookie", "__cfduid=d76231c8cccdbd5303a7d4feeb3f3a11f1466541718; _gat=1; _ga=GA1.2.1292204706.1466541721; request_method=POST; _session_id=5dc49c7814d5087ac51f9d9da20b2680")
            .data("dnt", "1")
            .data("upgrade-insecure-requests", "1")
            .data("user-agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36")
            .post();

问题是什么???

1 个答案:

答案 0 :(得分:1)

问题是,.data()添加了表单数据,而不是标题。因此,您需要使用适当的方法来设置相关信息。请参阅以下内容以修复您的代码:

设置标题:

.header("key", "value")

设置表单数据:

.data("key", "value")

设置用户代理:

.userAgent("Mozilla...")