2

是否有可能为 Jsoup 连接设置 Accept-Language 参数。我试过:

Jsoup.connection(url).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0").get();
Jsoup.connection(url).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();

但不起作用...

4

1 回答 1

13

您必须将其添加HeaderConnection下面提到的类似内容中

Jsoup.connection(url)
        .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0")
        .header("Accept-Language", "en")
        .header("Accept-Encoding","gzip,deflate,sdch");//can add as many as you like
        .get();
于 2013-06-27T09:41:52.050 回答