Search code examples
c#curlwebrequest

Emulating Curl --user --insecure in c#


I have the following Curl Call that works.

curl --insecure --user user@applicationname:password "https://someURL"

I cannot for the life of me get HttpWebRequest to emulate this.

Currently I am trying

 var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://someURL);
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Accept = "*/*";
        httpWebRequest.Method = "POST";
        httpWebRequest.Headers["Authorization"] = "Basic " +    Convert.ToBase64String(Encoding.ASCII.GetBytes("USER@Account:Password"));

I am getting the error Authentication failed because the remote party has closed the transport stream

I am guessing it has to do with the curl command having the insecure option but I cannot for the life of me see how to do this in the request.

Do to network restrictions/policies I cannot download restSharp or any other 3rd party libraries...


Solution

  • Add this line before doing the request

    System.Net.ServicePointManager.ServerCertificateValidationCallback = (obj, X509certificate, chain, errors) => true;