Jsoup problem --- failed to get http request org. jsoup. UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml + xml., jsoupxhtml

Source: Internet
Author: User

Jsoup problem --- failed to get http request org. jsoup. UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml + xml., jsoupxhtml
Jsoup problem --- failed to get http Request

1. Problem: When Jsoup is used to obtain data from some websites, it was obtained smoothly at first. However, when a wave of data is accessed, Jsoup reports an error. It should be the request type (ContextType) in the request header) does not meet the requirements.

Error message:

Exception in thread "main" org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/json; charset=utf-8, URL=...at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:547)at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:493)at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:205)at org.jsoup.helper.HttpConnection.get(HttpConnection.java:194)at com.Interface.test.JsoupUtil.httpGet(JsoupUtil.java:30)at com.Interface.test.test.main(test.java:23)

Request Method:

Public static String httpGet (String url, String cookie) throws IOException {// GET request Connection con = Jsoup. connect (url); // Request Header settings, especially cookie settings con. header ("Accept", "text/html, application/xhtml + xml, */*"); con. header ("Content-Type", "application/x-www-form-urlencoded"); con. header ("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); con. header ("Cookie", cookie); // parse the request result Document doc = con. get (); // get the title System. out. println (doc. title (); return doc. toString ();}

2. Solution: Add ignoreContentType (true) to Connection con = Jsoup. connect (url);. ignoreContentType (true) indicates that ContextType check is ignored.

After adding

// Obtain the request Connection con = Jsoup. connect (url ).IgnoreContentType (true );

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.