我想从网站下载图片,但该网站需要提供用户会话cookie,因此可以打开带有图片的网址。我尝试使用WebClient()
并发送Cookie,但网址仍未打开。
编辑:如果我client.DownloadData(url)
,它会将图片下载到字节中,因此可以正确访问它。但是,如果我使用Picasso
下载图片,则无效。
应用程序输出是这样的:
[Mono] Assembly Ref addref App[0xb4710760] -> Picasso[0xb4710ca0]: 2
[Settings] Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
[System.err] remove failed: ENOENT (No such file or directory) : /data/data/***********/cache/picasso-cache/journal.tmp
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isShipBuild true
[System.out] (HTTPLog)-Thread-5078-732856181: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
[System.out] (HTTPLog)-Thread-5078-732856181: SMARTBONDING_FEATURE_ENABLED is true
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
代码:
public void DownloadImage(string url, Context context, ImageView imageView) {
ISharedPreferences pref = context.GetSharedPreferences("UserSession", FileCreationMode.Private);
string cookie = pref.GetString("PHPSESSID", string.Empty);
using (var client = new WebClient()) {
client.Headers.Add(HttpRequestHeader.Cookie, "PHPSESSID=" + cookie);
Picasso.With(context).Load(url).Into(imageView);
}
}