Skip to main content
Home Forums Silverlight Programming Programming with .NET - General WebClient Download Failure For Certain URL
16 replies. Latest Post by brown950 on May 5, 2008.
(0)
brown950
Member
20 points
14 Posts
05-03-2008 5:44 AM |
I'm trying to use the WebClient to retrieve data from a page but it never works, always resulting in the error message: Download Failure. I do have the necessary cross-domain XML files in place and I have tested using the WebClient to retrieve other files from this site with no problem. I've been doing a lot of testing and the problem seems to be the URL, but I'm not sure how to fix that.
An example of the URL in question is: http://localhost:8080/html.ng/network=fim&size=movepre&property=foo&pagetype=bar¶ms.styles=html_vod&special=hlutest
However, if the URL were something like: http://localhost:8080/testdata.txt, it loads fine.
I tested this out using Apache and some rewrite rules to rewrite anything looking like the first URL or something like /foo to a static text file. Both URLs work fine in my browser, but the first ALWAYS fails in Silverlight 2 while the second always works.
However, I did create a WinForms application and it works fine using the first URL. So I'm not sure if this is an issue with the Silverlight WebClient or Uri class.
Any suggestions?
swildermuth
Star
8320 points
1,546 Posts
05-03-2008 5:50 PM |
No good suggestion, my guess is that since you're URI doesn't have traditional query string syntax that the URI class is choking on the syntax. That seems like a bug in Silverlight, not necessarily something for you to fix on the server.
05-03-2008 5:52 PM |
Sorry for the mulitple posts...the AJAX driven reply window is freaking out (and submitted the form as I typed).
One thing you can try is to URL encode it using HtmlUtility.UrlEncode().
05-03-2008 7:49 PM |
Na, no luck with that. I guess it is a Silverlight problem as it works fine in a WinForms app. I went ahead and posted a thread in the bug forum, hopefully it'll get some attention. Thanks for your suggestion though.
mchlsync
14606 points
2,730 Posts
05-04-2008 2:45 AM |
brown950:Na, no luck with that. I guess it is a Silverlight problem as it works fine in a WinForms app. I went ahead and posted a thread in the bug forum, hopefully it'll get some attention. Thanks for your suggestion though.
Can you show me which code you wrote at that side?
I have tested like this and it works.
05-04-2008 9:55 AM |
So, the issue is the URL I'm using. It's not something I have control over either except in my test environment. Below is the code from my test SL and WinForms apps. The SL one always fails, the WinForms one works. In my thread in the bug forum which you replied to I did detail the steps necessary to reproduce it. You simply need to setup a server that lets you access something (in my case a static text file), using a url such as: /html.ng/network=fim&size=movepre&property=ign&pagetype=e3_video_stream¶ms.styles=html_vod&special=hlutest
For that I used Apache and mod_rewrite with this rule: RewriteRule ^/html\.ng/ /testdata.txt
Here's the SL code:
namespace SilverlightApplication2{ public partial class Page : UserControl { public Page() { InitializeComponent(); PollServer(); } private void PollServer() { WebClient request = new WebClient(); request.DownloadStringCompleted += new DownloadStringCompletedEventHandler(request_DownloadStringCompleted); request.DownloadStringAsync(new Uri("http://localhost:8080/html.ng/network=fim&size=movepre&property=ign&pagetype=e3_video_stream¶ms.styles=html_vod&special=hlutest")); } void request_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { Status.Text = e.Error.Message; } else {
Status.Text = e.Result; } } }}
And the WinForms test:
namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); WebClient req = new WebClient(); req.DownloadStringCompleted += new DownloadStringCompletedEventHandler(req_DownloadStringCompleted); req.DownloadStringAsync(new Uri("http://localhost:8080/html.ng/network=fim&size=movepre&property=ign&pagetype=e3_video_stream¶ms.styles=html_vod&special=hlutest")); } void req_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { textBox1.Text = e.Result; } } }}
05-04-2008 10:25 PM |
brown950: You simply need to setup a server that lets you access something (in my case a static text file), using a url such as: /html.ng/network=fim&size=movepre&property=ign&pagetype=e3_video_stream¶ms.styles=html_vod&special=hlutestFor that I used Apache and mod_rewrite with this rule: RewriteRule ^/html\.ng/ /testdata.txt
You simply need to setup a server that lets you access something (in my case a static text file), using a url such as: /html.ng/network=fim&size=movepre&property=ign&pagetype=e3_video_stream¶ms.styles=html_vod&special=hlutest
I don't have Apache server at my office. I will try this at my home.. I just need to put testdata.txt in htdocs folder and update the mod_rewrite? I will test and will let you know the result.
05-04-2008 10:59 PM |
Yes, drop a file named "testdata.txt" into your htdocs directory and add the following to your httpd.conf.
RewriteEngine onRewriteRule ^/html\.ng/ /testdata.txt
Karen Co...
40 points
5 Posts
05-05-2008 1:30 PM |
Hi,
The character limitation for cross-domain paths is by design in Beta1 as a security mitigation. You can read more about the motivations in this blog post: http://scorbs.com/2008/04/15/silverlight-http-networking-stack-part-2-cross-domain-communication-overview
Right now, cross domain paths can include:
- Alphanumeric chars
- '/', '~', "-', "_", "." (But no ".."s or "./" substrings)
We've already heard that ';', '=', and ',' are character limitations that are problematic, and we're addressing those for Beta2. If you have additional blocked characters that are preventing you from accomplishing your scenario, we would love to hear about htem.
Thanks!Karen
05-05-2008 5:57 PM |
Ah, well thank you for clearing that up. Guess I'm looking forward to beta 2 even more.
Also not allowing "&" would be problematic at least in my case.
Maybe you guys could just add a new attribute to the clientaccesspolicy.xml to disable that limitation for certain domains.