2016-06-21 32 views
1

我試圖通過這個頁面的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=descJSoup.connect一些要求具有403錯誤

,但是,我有錯誤: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

問題是,.data()添加到表單數據,而不是標題。所以你需要使用適當的方法來設置相關的信息。參考下面的修正您的代碼:

要設置標頭:

.header("key", "value")

要設置形式的數據:

.data("key", "value")

要設置用戶代理:

.userAgent("Mozilla...")