views:

607

answers:

2

Hi, I'm trying to download a file from my provider.

The url is protected with basic username and password, and everything is sent over ssl.

So I try to do this:

        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"));

As you can see I try to validate. The url is correct, and the code works when I try to download something from twitter.

And the URL works when I type it in in Firefox / Internet Explorer

What am I forgetting to connect to this xml file?

The error I get is the following:

And I am using Visual Studio 2010 (the full, not Express), and the CTP refresh :)

+2  A: 

Apparently it goes wrong when you try to do an SSL request. Authentication over SSL is not supported in Silverlight (throws a not notimplementedException) in REGULAR Silverlight.

So I'm pretty sure this is the same problem in WP7.

Snake
I see the same thing when I try to access Google ClientLogin. I though it was just me. One of the perils of CTPs. They'd better fix this before they ship.
ageektrapped
But it also occurs in regular Silverlight. That's why I'm worried...
Snake
+6  A: 

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);
John Sheehan
I haven't tried the beta yet. I will. Soon :P Thanks!
Snake