Your code should be modified as follows:
httpClient.BaseAddress = new Uri("https://foobar.com/");
You must use the https: URI scheme. There is a useful page here on MSDN about secure HTTP connections. Really:
Use the https: URI scheme
The HTTP protocol defines two URI schemes:
http: used for unencrypted connections.
https: Used for secure connections that must be encrypted. This option also uses digital certificates and certification authorities to verify that the server is who it claims to be.
Also, keep in mind that HTTPS connections use an SSL certificate. Make sure your secure connection has this certificate, otherwise the requests will fail.
EDIT:
The code works fine for creating http calls. But when I change the https scheme does not work, let me post an error message.
What does it mean doesn't work? Queries fail? Is an exception thrown? Specify your question.
If the requests fail, then the problem should be an SSL certificate.
To fix the problem, you can use the HttpWebRequest class and then its ClientCertificate property. You can also find here a useful example of how to make an HTTPS request using a certificate.
An example is as follows (as shown on the MSDN page previously linked):
//You must change the path to point to your .cer file location. X509Certificate Cert = X509Certificate.CreateFromCertFile("C:\\mycert.cer"); // Handle any certificate errors on the certificate from the server. ServicePointManager.CertificatePolicy = new CertPolicy(); // You must change the URL to point to your Web server. HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://YourServer/sample.asp"); Request.ClientCertificates.Add(Cert); Request.UserAgent = "Client Cert Sample"; Request.Method = "GET"; HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
Alberto Solano Mar 07 '14 at 13:48 2014-03-07 13:48
source share