SIlverlight使用WebClent下载图片出现的安全问题怎么解决
//开始上传
private void OKButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(this.txbaddress.Text)) {
this.txbMessage.Text = "请输入地址!";
}
else if (new Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?").Match(this.txbaddress.Text).Success == false)
{
this.txbMessage.Text = "图片地址格式必须是(http://....jpg)!";
}
else {
this.txbMessage.Text = "正在下载图片,请稍后...";
this.txbaddress.IsEnabled = false;
WebClient mywebclient = new WebClient();
string url = this.txbaddress.Text.Trim();
Uri endpoint = new Uri(url, UriKind.Absolute);
mywebclient.OpenReadCompleted += new OpenReadCompletedEventHandler(mywebclient_OpenReadCompleted);
mywebclient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(mywebclient_DownloadProgressChanged);
mywebclient.OpenReadAsync(endpoint);
}
}
void mywebclient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error != null)//这里一直报安全错误 谁遇到过
{
this.txbMessage.Text = "网络故障,下载失败!";
this.txbaddress.IsEnabled = true;
return;
}
if (e.Cancelled != true)
{
Stream clientStream = e.UserState as Stream;
Stream serverStream = (Stream)e.Result;
byte[] buffer = new byte[serverStream.Length];
serverStream.Read(buffer, 0, buffer.Length);
clientStream.Write(buffer, 0, buffer.Length);
clientStream.Close();
serverStream.Close();
}
}