访问魔兽世界军械库时WebClient安全错误
我正在尝试拼凑出一个问题的解决方案。 基本上我使用 Silverlight 4 和 C# 4.0 来访问魔兽世界军械库。 如果有人这样做了 - 请提供有效的 .net 4.0 代码。
我尝试运行的代码是(e.Error 包含安全错误):
private void button10_Click(object sender, RoutedEventArgs e)
{
string url = @"http://eu.wowarmory.com/guild-info.xml?r=Eonar&n=Gifted and Talented";
WebClient wc = new WebClient();
// HOW DO I ADD A USER AGENT STRING (RESPONSE MAY VARY (I.E. HTML VS XML) IF PAGE THINKS CALL IS NOT CAPABABLE OF SUPPORTING XML TRANSFORMATIONS)
//wc.ResponseHeaders["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)";
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri(url));
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string result = e.Result;
XDocument ArmouryXML = XDocument.Parse(result);
ShowGuildies(ArmouryXML);
}
else
{
MessageBox.Show("Something is complaining about security but not sure what!");
}
}
注释:
- C# 4.0
- Thearmory 是一个 XML 文件 - 但我相信如果请求不是来自 a,它会恢复为 html支持 XML 转换的浏览器。但我不认为我能走到这一步。
- 军械库上有一个跨域策略文件 - 这可能是错误的原因(不确定!
- 我已经上传到生产服务器
- 我正在使用 IIS 网站在本地测试它
- 我快疯了!
- 网站提出了这样的建议问题可以通过创建 WebProxy 来解决 - 但我不知道如何做到这一点
如果有人能够接受这个挑战并向我们展示我更喜欢一个,那就太好了。首先使用非代理解决方案,然后尝试使用代理。
错误详细信息:
e.Error = {System.Security.SecurityException ---> System.Security.SecurityException: 安全错误。 在 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在 System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5。
有聪明的编码大师可以在睡梦中解决这个问题吗?
如果您能提供帮助,谢谢。
I am trying to piece together a solution to a problem.
Basically I am using Silverlight 4 with C# 4.0 to access the world of warcraft armoury.
If anyone has done this - please oh please provide the working .net 4.0 code.
The code I am attempting to run is (e.Error contains a securtiy error):
private void button10_Click(object sender, RoutedEventArgs e)
{
string url = @"http://eu.wowarmory.com/guild-info.xml?r=Eonar&n=Gifted and Talented";
WebClient wc = new WebClient();
// HOW DO I ADD A USER AGENT STRING (RESPONSE MAY VARY (I.E. HTML VS XML) IF PAGE THINKS CALL IS NOT CAPABABLE OF SUPPORTING XML TRANSFORMATIONS)
//wc.ResponseHeaders["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)";
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri(url));
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string result = e.Result;
XDocument ArmouryXML = XDocument.Parse(result);
ShowGuildies(ArmouryXML);
}
else
{
MessageBox.Show("Something is complaining about security but not sure what!");
}
}
Notes:
- C# 4.0
- The armoury is an XML file - but i believe it reverts to html should the request not be from a browser that supports XML transformation. But i don't think I am getting this far.
- The armoury has a cross domain policy file on it - this may be the cause of the error (not sure!
- I have uploaded to a production server
- I am testing it locally using IIS website
- I am going insane!
- Websites have made the suggestion that this problem can be overcome by creating a WebProxy - but I haven't the first clue how to do this.
It would be great if someone could take on this challenge and show us all that it is possible. I'd prefer a non-proxy solution first, then try a proxy.
The error details:
e.Error = {System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.
Any intelligent master coders out there who can solve this in their sleep?
Thanks if you can help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在浏览器中运行 Silverlight 应用程序时,silverlight 应用程序只能向来自与安装该应用程序相同的域的 URL 发出请求。例如,如果您的 silverlight 应用程序是从
http://yoursite.com/yourapp.xap
安装的,则您只能向http://yoursite.com/ 上的其他 URL 发出 WebClient 请求
。您可以选择创建一个代理脚本来从您的服务器请求 WoW 军械库,然后让您的 silverlight 应用程序访问该代理,或者在浏览器外运行 silverlight 并请求完全信任。编辑:通常,最好的选择是跨域策略文件,如此处所述。遗憾的是,wowarmory.com 似乎没有实现跨域策略文件。
When running a Silverlight application in a browser, the silverlight application may only make requests to URLs from the same domain as the application was installed from. For instance, if your silverlight app is installed from
http://yoursite.com/yourapp.xap
, you can only make WebClient requests to other URLs onhttp://yoursite.com/
. Your options here are either create a proxy script that requests the WoW armory from your server, and have your silverlight app hit that proxy, or run the silverlight out-of-browser and request full trust.Edit: Generally the best option is a cross-domain policy file as explained here. Sadly, It does not appear that wowarmory.com implements the cross-domain policy file.
你走在正确的轨道上,你只需要设置用户代理。
you were on the right track, you just need to set the user-agent.
已解决 - 由于跨域安全性和标头修改限制,使用 WCF 服务充当代理。感谢您的所有建议。
SOLVED - used a WCF service to act as a proxy due to cross domain security and header modification restrictions. Thanks for all the advice.