Windows Phone 7的,下载的XML通过SSL认证 [英] Windows Phone 7, download xml over ssl with authentication
问题描述
我想从我的供应商处下载一个文件。
I'm trying to download a file from my provider.
URL是保护基本的用户名和密码,一切都通过SSL发送。
The url is protected with basic username and password, and everything is sent over ssl.
所以,我尝试这样做:
WebClient proxy = new WebClient();
proxy.DownloadStringCompleted += (o, dscea) => System.Diagnostics.Debugger.Break();
proxy.Credentials = new NetworkCredential("username", "password");
proxy.DownloadStringAsync(new Uri("https://..../.../data.xml"));
正如你可以看到我尝试验证。网址是正确的,code工作时,我尝试下载从Twitter的东西。
As you can see I try to validate. The url is correct, and the code works when I try to download something from twitter.
当我键入它在Firefox / Internet Explorer中的URL的作品
And the URL works when I type it in in Firefox / Internet Explorer
我是什么忘了连接到这个xml文件?
What am I forgetting to connect to this xml file?
我得到的错误是:
- [System.Net.WebException] {[HttpWebRequest_WebException_RemoteServer] \ r \ nArguments:NOTFOUND \ r \ nDebugging 资源字符串不可用。 通常情况下,密钥和参数提供 足够的信息来诊断 问题。看到 <一href="http://go.microsoft.com/fwlink/?linkid=106663&Version=3.7.50308.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer" rel="nofollow">http://go.microsoft.com/fwlink/?linkid=106663&Version=3.7.50308.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer } System.Net.WebException
- [System.Net.WebException] {"[HttpWebRequest_WebException_RemoteServer]\r\nArguments:NotFound\r\nDebugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=3.7.50308.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer "} System.Net.WebException
和我正在使用Visual Studio 2010(完整,没有防爆preSS),以及CTP刷新:)
And I am using Visual Studio 2010 (the full, not Express), and the CTP refresh :)
推荐答案
这似乎是固定在测试版工具发布。我不得不直接设置授权头,虽然作为.NET不处理基本身份验证你所期望的方式。这是我的工作code片断:
This appears to be fixed in the Beta tools release. I had to set the Authorization header directly though as .NET doesn't handle basic auth the way you might expect. Here's my working code snippet:
var client = new WebClient();
var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password)));
var authHeader = string.Format("Basic {0}", token);
client.Headers["Authorization"] = authHeader;
client.DownloadStringCompleted += (s, e) =>
{
// handle result
};
client.DownloadStringAsync(url);
这篇关于Windows Phone 7的,下载的XML通过SSL认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!