JSoup.connect 一些请求有 403 错误
JSoup.connect with some requests has 403 error
我尝试通过此页面的 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();
有什么问题???
问题是,.data()
添加到表单数据,而不是 header。所以你需要使用合适的方法来设置相关信息。请参考以下内容来修复您的代码:
设置header:
.header("key", "value")
设置表单数据:
.data("key", "value")
设置用户代理:
.userAgent("Mozilla...")
我尝试通过此页面的 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();
有什么问题???
问题是,.data()
添加到表单数据,而不是 header。所以你需要使用合适的方法来设置相关信息。请参考以下内容来修复您的代码:
设置header:
.header("key", "value")
设置表单数据:
.data("key", "value")
设置用户代理:
.userAgent("Mozilla...")