0
点赞
收藏
分享

微信扫一扫

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

承蒙不弃 2022-04-02 阅读 33


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<String, String> header = new HashMap<String, String>();
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检查



举报

相关推荐

0 条评论