We have a rest service which works fine over http. I use the following C# code to post data to it:
string postData = [contains the data to post]
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var baseAddress = "http://www.myserver.net/rest/saveData";
System.Net.WebRequest req = System.Net.WebRequest.Create(baseAddress);
string authInfo = "username:password";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
req.Headers["Authorization"] = "Basic " + authInfo;
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postData);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();
System.Net.WebResponse resp = req.GetResponse();
var s = resp.GetResponseStream();
var sr = new System.IO.StreamReader(s);
var r= sr.ReadToEnd().Trim();
Now if change this to SSL, replacing the http call with a https call:
"https://www.myserver.net/rest/saveData";
This does not work, as it timeout at the GetReponse call. First I thought is was caused by a self signed certificate, but this is not the case as I use:
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Which accepts all certificates. The error I get is something like zero bytes returned on transportlayer (it is in my language, so I don't know exactly what the english exception is)
I use CURL on the commandline to test the calls and there it works both on http and SSL, so the rest service seems to fine.
Does anybody have an idea why it does not work over SSL?
Thanks