UnsupportedMimeTypeException about Jsoup

Source: Internet
Author: User

Execution of the following code: [java] Jsoup. connect (baseURL + datajssrc0000.exe cute (); throws an Exception: [java] org. jsoup. unsupportedMimeTypeException: Unhandled content type. must be text/*, application/xml, or application/xhtml + xml. mimetype = application/x-javascript, URL = http://www.abc.com/playdata/206/8910.js? 44613.77 </del> but when I use [java] URLConnection conn = new URL (baseURL + dataJSSrc). openConnection (); it is OK! In the following code [java] System. out. println (conn. getContentType (); // out put 'application/x-javascript 'Can Jsoup only be used to download HTML or XML? The answers: you can use Jsoup to download anything you like. by default, Jsoup will throw an exception if it retrieves content with a mime type that it will not be able to parse as HTML, to avoid parsing e.g. images. however you can disable that testwithconnection. ignoreContentType (true) if you just want to get at the bytes or as a string: Here is an action to avoid throwing the exception in your code method: [java] String script = jsoup.connect(jsurl).ignorecontenttype(true0000.exe cute (). body (); or [java] byte [] bytes = jsoup.connect(imageurl).ignorecontenttype(true0000.exe cute (). bodyAsBytes (); You will get more control with a full-fledged HTTP client, but this method can be useful in a pinch. collect data from Stack Overflow onhttp: // stackoverflow.com/

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.