我正在使用以下代码从服务器下载图像但失败。我正在使用服务器身份验证,请帮忙
private BitmapImage getimage (string uri)
{
var webRequest = WebRequest.Create(uri);//making a variable webrequest,
webRequest.Credentials = new NetworkCredential("user", "password");//credential is using for authentication
using (var webResponse = webRequest.GetResponse())//use for stucking problem of button
{
using (var responseStream = webResponse.GetResponseStream())
{
BitmapImage img = new BitmapImage();
img.BeginInit();
img.StreamSource = responseStream;
img.EndInit();
return img;
}
}
}