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
Fred
code1 (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");
}
error
baseurl=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)