HTTP错误提取URL。状态= 500

时间:2015-12-12 01:35:10

标签: java android jsoup last.fm

我正在尝试使用last.fm api和Jsoup connect

检索音乐播放器的艺术家照片
protected Bitmap doInBackground(String... strings) {
    Bitmap bmp;
    try {
        Document doc = Jsoup.connect(mArtisName).parser(Parser.xmlParser()).post();
        mArtisName = doc.select("image[size=extralarge]").text();
        bmp = cache.get(Artis);
        if (bmp==null) {
            URL url = new URL(mArtisName);
            URLConnection update = url.openConnection();
            InputStream is = update.getInputStream();
            bmp = BitmapFactory.decodeStream(is);
            cache.put(Artis, bmp);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        bmp = defaultBitmap;
    }
    return bmp;
}

logcat的:

12-12 07:26:54.436    2363-2386/com.karyaanaknegeri.musikq W/System.err﹕ org.jsoup.HttpStatusException: HTTP error fetching URL. Status=500, URL=http://img2-ak.lst.fm/i/u/300x300/751c067c9cb6469b9d6d2e33e1791edc.png%20http://img2-ak.lst.fm/i/u/300x300/be563302f6574b3c800b2308970777b6.png%20http://img2-ak.lst.fm/i/u/300x300/15fe26485bc54344bb43d7d05705c46d.png%20http://img2-ak.lst.fm/i/u/300x300/5d54245519f74844806c7918545c6e88.png%20http://img2-ak.lst.fm/i/u/300x300/37696a0d07f849f5bdd34cac656a218e.png%20http://img2-ak.lst.fm/i/u/300x300/3a66a1890a9b4c9d8bf88a8c6d88868d.png

1 个答案:

答案 0 :(得分:1)

问题解决了

Connection connection = Jsoup.connect(mArtisName).ignoreContentType(true).ignoreHttpErrors(true);
Connection.Response resp = connection.execute();
Document document;
if (resp.statusCode() ==200) {
    document = connection.parser(Parser.xmlParser()).post();
    urlArtis = document.select("image[size=extralarge]").text();
}