繁体   English   中英

如何使用Silverlight应用程序中的C#获取URL内容?

[英]How to get URL content using C# from silverlight application?

我使用下面的代码从silverlightlight应用程序中获取给定URL的内容,但出现错误:

“ System.Windows.dll中发生类型'System.Security.SecurityException'的异常,但未在用户代码中处理”

我检查了对Silverlight应用程序的信任度。 但是什么都没有改变!

private void StartWebRequest(string url)
{
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
   request.BeginGetResponse(new AsyncCallback(FinishWebRequest),request);
}

 private void FinishWebRequest(IAsyncResult result)
{
   HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
}

为了避免上述错误,我将FinishWebRequest函数更改为:

private void FinishWebRequest(IAsyncResult result)
{
      HttpWebRequest req = (HttpWebRequest)result.AsyncState;
      HttpWebResponse response = (HttpWebResponse)req.EndGetResponse(result) ;
}

有人可以说发生了什么事吗?

解决方案是将跨域xml文件放在托管服务的根目录中,这此进行说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM