External Libraries Java Exceptions

Jsoup Fix Connection error: org.jsoup.UnsupportedMimeTypeException

Jsoup Connection error: org.jsoup.UnsupportedMimeTypeException example shows how to fix Jsoup Connection error: org.jsoup.UnsupportedMimeTypeException error while using Jsoup.

How to fix Connection error: org.jsoup.UnsupportedMimeTypeException?

By default, Jsoup supports below given content types.
1) text/*
2) application/xml
3) application/xml+xhtml

If you are trying to parse any page whose content type is not one of the above content types, Jsoup throws “Connection error: org.jsoup.UnsupportedMimeTypeException” exception as given below.

Output

We have used JSON test API hosted at http://ip.jsontest.com/ which gives user’s IP address in JSON format. The content type returned by the API is “application/json” which is not supported by Jsoup by default, hence the exception “org.jsoup.UnsupportedMimeTypeException: Unhandled content type”.

How to resolve it?

You can use ignoreContentType method of Connection class to ignore the content type returned by the webpage.

Passing true in the method ignores the document’s content type while parsing the response.

Example

Output

Please let us know your views in the comments section below.

Tags

About the author

rahimv

rahimv

rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

  • SANJAY GUPTA

    respected sir

    can you make a java program to search a query and returns the URL as a result like google search engine ??

    please send me the code in my email : rspvsanjay@gmail.com

    • rahimv

      I can’t send you the code. But if you have a requirement, have a look at Apache Solr.

Join 1000+ fellow learners! Enter your email address below: