문제

I am parsing web pages in auto mode with JSOUP and get such error: org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=image/jpeg,

As solution, it is offered here to use ignoreContentType() function that will 'force jsoup to ignore the content-type and parse the response as HTML'. I do not want to parse picture as HTML, so is there any way to handle such exceptions or get content type like:

if (Contenttype == 'text' or Contenttype  == 'xml' or ...what_ever_other_text_format)
   parse
else
   do_nothing.
도움이 되었습니까?

해결책

use HttpConnection.Response's method contentType to get content type and decide accordingly

Connection.Response res = Jsoup.connect("http://www.google.com/").timeout(10*1000).execute();

String contentType=res.contentType();

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top