Skip to main content
Home Forums Silverlight Programming Programming with .NET - General webClient DownloadStringAsync failed
6 replies. Latest Post by pbromberg on October 26, 2008.
(0)
work2gs
Member
58 points
79 Posts
10-24-2008 2:34 AM |
Hi
I successfully send http request from winform C# application (see code1)but from silverlight (see code2) I obtain an error.(see error)
Peharps the problem is that my server is https and the remote is also https.
How I modify my server to be http ???
Thanks in advance Fredcode1 (Winform C# succeeded) private void button1_Click(object sender, EventArgs e) { try { WebClient client = new WebClient(); // Add a user agent header in case the requested URI contains a query. client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); client.QueryString.Add("user", "AAA"); client.QueryString.Add("password", "1111111"); client.QueryString.Add("api_id", "3126312"); client.QueryString.Add("to", "972545665417"); client.QueryString.Add("text", "This is an example message"); string baseurl = "http://api.clickatell.com/http/sendmsg"; Stream data = client.OpenRead(baseurl); StreamReader reader = new StreamReader(data); string s = reader.ReadToEnd(); data.Close(); reader.Close(); MessageBox.Show(s); } catch (Exception ex) { MessageBox.Show(ex.Message); } }code2 (silverlight failed)private void sendSMS() { WebClient client = new WebClient (); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); string baseurl ="http://api.clickatell.com/http/sendmsg"; baseurl +="?user=AAA"; baseurl +="&password=1111111"; baseurl +="&api_id=3126312"; baseurl +="&to=972545665417"; baseurl +="&text=This+is+an+example+message"; Uri uri = new Uri(baseurl, UriKind.Absolute); client.DownloadStringAsync(new Uri(baseurl)); } void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { string s = e.Result.ToString(); Debugger.Log(0, "debug", "s=" + s+ "\r\n"); } else Debugger.Log(0, "debug", "error=" + e.Error.ToString()+ "\r\n"); } errorbaseurl=http://api.clickatell.com/http/sendmsg?user=AAA&password=1111111&api_id=3126312&to=972545665417&text=This+is+an+example+message 'iexplore.exe' (Silverlight): Loaded 'C:\Program Files\Microsoft Silverlight\2.0.31005.0\en-US\mscorlib.debug.resources.dll' error=System.Security.SecurityException ---> System.Security.SecurityException: Security error. at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState) at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState) --- End of inner exception stack trace --- at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
robhouwe...
Contributor
3184 points
548 Posts
10-25-2008 2:57 AM |
Have you created a crossdomain file on your server? The error you're getting looks like a crossdomain security issue.
10-25-2008 2:15 PM |
Thanks for your response
I define a clientaccesspolicy.xml in my web application that contains this
<?xml version="1.0" encoding="utf-8"?><access-policy> <cross-domain-access> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </cross-domain-access></access-policy>
without success
Could you tell me what is missing ?
thanks
Fred
Evs_
71 Posts
10-26-2008 3:56 AM |
try to install fiddler to check if someone is wrong ;)...have a look to my old post: http://silverlight.net/forums/t/39985.aspx
10-26-2008 5:12 AM |
Do you mean that the remote server (api.clickatell.com)
I try to access have to be the clientaccesspolicy.xml existing ?
This is what I obtain from Fiddler
GET http://api.clickatell.com/clientaccesspolicy.xml404 Not Found
.REQUEST { font: 8pt Courier New; color: blue;} .RESPONSE { font: 8pt Courier New; color: green;}GET /clientaccesspolicy.xml HTTP/1.1Accept: */*Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)Host: api.clickatell.comProxy-Connection: Keep-AliveHTTP/1.1 404 Not FoundVia: 1.1 Address Is HiddenConnection: Keep-AliveProxy-Connection: Keep-AliveContent-Length: 304Date: Sun, 26 Oct 2008 08:57:58 GMTContent-Type: text/html; charset=iso-8859-1Server: Apache/2.2.3 (Red Hat)Keep-Alive: timeout=10, max=50
Thanks
10-26-2008 5:28 AM |
HI, as you can see, clientpolicy.xml must be on the server( your application tries to download it but it can't find)....
So you have to put it on the server, not in your application ;)
Mark this post as answer if it solves your problem ;)
Bye
pbromberg
2128 points
370 Posts
10-26-2008 8:31 AM |
Have a look at their crossdomain.xml policy file and you'll see why Siliverlight will not let you do this:
http://api.clickatell.com/crossdomain.xml
What you need to do is create your own service on the same server that your Silverlight App is served from, and have that service make the call.