问题描述
我正试图拼凑出解决问题的方法.基本上,我使用带有C#4.0的Silverlight 4来访问魔兽世界.如果有人这样做-请哦,请提供有效的.net 4.0代码.
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!");
}
}
注释:
- C#4.0
- 军械库是一个XML文件-但我认为,如果请求不是来自支持XML转换的浏览器,它将还原为html.但是我不认为我能走这么远.
- 军械库上有一个跨域策略文件-这可能是导致错误的原因(不确定!
- 我已上传到生产服务器
- 我正在使用IIS网站在本地进行测试
- 我要疯了!
- 网站提出了可以通过创建WebProxy来解决此问题的建议-但我尚不清楚如何做到这一点.
如果有人能够接受这一挑战并向我们展示一切可能,那就太好了.我希望先使用非代理解决方案,然后再尝试使用代理.
错误详细信息:
e.Error = {System.Security.SecurityException ---> System.Security.SecurityException:安全错误. 在System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在System.Net.Browser.BrowserHttpWebRequest中.<> c__DisplayClass5.
外面有什么聪明的主编码员可以在睡眠中解决这个问题吗?
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?
谢谢您的帮助.
推荐答案
已解决-由于跨域安全性和标头修改限制,使用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.
这篇关于访问魔兽世界的WebClient安全错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!