[英]Why WebClient not displaying web page?
The code below compiles but it does not display the text or photos of the website. 下面的代码可以编译,但不显示网站的文本或图片。 I just want to run a program that involves HTTP communication with Silverlight. 我只想运行一个涉及与Silverlight进行HTTP通信的程序。 Any idea why I am not getting the website to display? 知道为什么我没有让网站显示吗? I just get "error occurred" in the textBlock to display instead 我只是在textBlock中显示“发生错误”,而是显示
namespace SilverlightApplication4
{
public partial class MainPage : UserControl
{
string baseUri = "http://yahoo.com";
WebClient client = new WebClient();
public MainPage()
{
InitializeComponent();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
client.DownloadStringAsync(new Uri(baseUri));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
textBox.Text = "Using WebClient: "+ e.Result;
else
{
textBox.Text = e.Error.Message;
textBlock.Text = "error occurred";
}
}
}
}
It is a crossdomain issue where the xml is not present in the server as a result you are getting the exception 这是一个跨域问题,由于您正在获取异常,因此服务器中不存在xml
Heres a link where I found the issue you can go through it 这是我发现您可以解决的问题的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.