Jsoup Fix Connection error: org.jsoup.UnsupportedMimeTypeException

This example shows how to fix the Jsoup Connection error: org.jsoup.UnsupportedMimeTypeException error while using the 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 the JSON test API hosted at http://ip.jsontest.com/ which gives the 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

This example is a part of the Jsoup tutorial with examples.

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

About the author

RahimV

RahimV

My name is RahimV and I have over 16 years of experience in designing and developing Java applications. Over the years I have worked with many fortune 500 companies as an eCommerce Architect. My goal is to provide high quality but simple to understand Java tutorials and examples for free. If you like my website, follow me on Facebook and Twitter.

2 Comments

Your email address will not be published. Required fields are marked *

Online Shopping