web-dev-qa-db-fra.com

Erreur de connexion: "org.jsoup.UnsupportedMimeTypeException: type de contenu non géré"

Lorsque j'essaie d'ouvrir un lien pour analyser avec jsoup j'obtiens une erreur.

Commande de connexion: 

Document doc = Jsoup.connect("http://www.rfi.ro/podcast/emisiune/174/feed.xml")
                .timeout(10 * 1000).get();

Erreurs renvoyées:

Exception in thread "main" org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/rss+xml; charset=utf-8, URL=http://www.rfi.ro/podcast/emisiune/174/feed.xml
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.Java:453)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.Java:410)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.Java:164)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.Java:153)
    at podcast.Pods.main(Pods.Java:41)
25
user2340897

Utilisez ignoreContentType() ( voir le doc ici ):

String myURL = "http://www.rfi.ro/podcast/emisiune/174/feed.xml";
Document pod = Jsoup.connect(myURL).ignoreContentType(true).get();
51
acdcjunior
// Initialize UnSupportedMimeTypeExeception class 
UnsupportedMimeTypeException mimeType = new UnsupportedMimeTypeException("Hey this is Mime",  "application/json", "http://dictionary.cambridge.org/dictionary/english/reality");
String mime = mimeType.getMimeType();

Document doc = Jsoup.connect("https://translate.google.com/translate_a/single?client=t&sl=en&tl=hi&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&source=bh&ssel=0&tsel=0&kc=1&tk=2546.416541&q=consume")
    .requestBody("JSON")
    .header("Content-Type", mime)
    .cookies(response.cookies())
    .ignoreContentType(true)
    .post();
System.out.println(doc);
0
Vipul Jurel