Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, appl

Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/

 

错误代码:

org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/json;charset=UTF-8, URL=http://search.gmw.cn/service/search.do?q=%E4%B8%80%E5%B8%A6%E4%B8%80%E8%B7%AF&c=n&cp=1

googl找到个方法

 

Connection connection = Jsoup.connect(url);
            Map header = new HashMap();
            header.put(
                    "Accept",
                    "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            header.put("Accept-Encoding", "gzip, deflate");
            header.put("Accept-Language", "zh-CN,zh;q=0.9");
            header.put("Cache-Control", "max-age=0");
            header.put("Connection", "close");
            header.put(
                    "User-Agent",
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64;X11; Linux 64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36");
            doc = connection.ignoreContentType(true).headers(header)
                    .timeout(30000).get();

加了个    .ignoreContentType(true)    

忽略ContentType检查

 

你可能感兴趣的:(jsoup)