1

I have the following C# code that is attempting to make an https request to a specific url. If I change the URL to point to the QAS server, which is not https then all works fine. I have tried numerous combinations of settings, but nothing that I do seems to get this to work correctly. You can see several of the different combinations of things that I have done in the comments.

var request = (HttpWebRequest)WebRequest.Create(nextUrl);
request.AllowAutoRedirect = false;
request.UseDefaultCredentials = true;
request.KeepAlive = false;
//request.PreAuthenticate = true;
//request.Credentials = CredentialCache.DefaultNetworkCredentials;
//request.Credentials = new NetworkCredential("name", "pass", "domain");
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
HttpWebResponse response;
using (response = (HttpWebResponse)request.GetResponse())
{
    //Do Something
}
MethodMan
  • 18,625
  • 6
  • 34
  • 52
Paul Cavacas
  • 4,194
  • 5
  • 31
  • 60

1 Answers1

0

Your code for the certificate callback looks incorrect, it should look:

ServicePointManager.ServerCertificateValidationCallback =
     new RemoteCertificateValidationCallback(AcceptAllCertifications);

I'm assuming you have the proper method signature for the AcceptAllCertifications. Also the class you're utilizing if nextUrl is http it will default to unsecure, if it is https it will default to secure.

Greg
  • 11,302
  • 2
  • 48
  • 79
  • The callback is correct. If you put that full statement in that you have it works as well, but is not needed any longer and you can do the short hand that I have (I love resharper). Also as I stated the URL is https. When I change it to point to a test server for http then it works fine, but in this case it is https that is failing. – Paul Cavacas Dec 01 '16 at 17:09
  • I don't have ReSharper, so good to know. Are you explicitly putting **https** in the parameter? Also, you should try modifying the user agent to state that it is required. – Greg Dec 01 '16 at 20:36
  • The URL does explicitly say https yes. How should I modify the client? – Paul Cavacas Dec 01 '16 at 21:49
  • Take a look: http://stackoverflow.com/questions/8284859/create-a-ssl-webrequest-with-c-sharp – Greg Dec 01 '16 at 23:50
  • I have tried all of the suggestions from the above link, but still get 401 unauthorized – Paul Cavacas Dec 05 '16 at 20:10