Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 7 WebBrowserTask problem

I'm trying to open this url using a WebBrowserTask in WP7, and it doesn't work (I get a custom error on our website), but when I type it in by hand, it works fine. Any ideas?

It also works perfectly fine in Google Chrome and IE7.

This is the url:

http://www.symfonee.com/Improv/addison/comedians/Bio.aspx?ShowDate=12/15/10&ShowTime=8:00p&Uid=54918a0d-1beb-4552-bdc8-2d474e3ea5ae

And this is my code:

string url = "http://www.symfonee.com/Improv/addison/comedians/Bio.aspx?ShowDate=12/15/10&ShowTime=8:00p&Uid=54918a0d-1beb-4552-bdc8-2d474e3ea5ae";

WebBrowserTask browser = new WebBrowserTask();
browser.URL = url;
browser.Show();

Thanks!

EDIT:

Without any of the solutions below, this code works fine:

WebBrowserTask browser = new WebBrowserTask();
browser.URL = "http://www.youtube.com/results?search_query=Windows+Phone+7&aq=f";
browser.Show();

I don't understand what is different?

like image 989
Carlo Avatar asked Dec 09 '10 01:12

Carlo


3 Answers

There is a bug with the SDK. In URL that contains &, you need to escape it.

For example:

... Uri.EscapeDataString("&") + "ShowTime=8:00p"

like image 119
samwize Avatar answered Sep 26 '22 15:09

samwize


This is most likely because your query string parameters are not URL-encoded. Modern web browsers will attempt to compensate when you paste that into the address bar because it's hard to URL-encode in your head. But when you're using an API, you should really URL-encode those pieces yourself.

Use the Uri.EscapeDataString method to encode each part of the query string individually. For example.

string url = "http://www.symfonee.com/Improv/addison/comedians/Bio.aspx" +
    "?ShowDate=" + Uri.EscapeDataString("12/15/10") +
    "&ShowTime=" + Uri.EscapeDataString("8:00p") +
    "&Uid=" + Uri.EscapeDataString("54918a0d-1beb-4552-bdc8-2d474e3ea5ae");
like image 25
Josh Avatar answered Sep 25 '22 15:09

Josh


The following code worked for me:

s = "www.. "; //url
s = Uri.EscapeUriString(s);
task.URL = HttpUtility.UrlEncode(s);
like image 41
fboscari Avatar answered Sep 26 '22 15:09

fboscari