您的位置:首页 > 移动开发 > Android开发

android 使用imageloader 获取图片时,如果需要带cookie

2015-07-20 18:08 519 查看
//universal imageloader获取图片时,若需要cookie,需在application中进行配置添加此类。

importandroid.content.Context;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import java.io.IOException;
import java.net.HttpURLConnection;

/**
 *
 */
public class CustomImageDownloader extends BaseImageDownloader {//universal image loader获取图片时,若需要cookie,
    // 需在application中进行配置添加此类。
    public CustomImageDownloader(Context context) {
        super(context);
    }

    @Override
    protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
        // Super...
        HttpURLConnection connection = super.createConnection(url, extra);
//        connection.setRequestProperty("Cookie", MyApplication.getInstance().getCookieString());
        connection.setRequestProperty("Connection", "keep-Alive");
        connection.setRequestProperty("User-Agent", "jsgdMobile");
        return connection;
    }
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息