Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

How to convert Curl request to Httpclient C#

$
0
0

Below curl request working fine but when i convert this request in c# web request then i got error.

curl request working fine:

curl --key private.pem --cert public.crt --data "{\"branch_reference\":\"123\"}" 
--header "Content-type: application/json; profile=https://realtime-listings.webservices.zpg.co.uk/docs/v1.2/schemas/listing/list.json"
https://realtime-listings-api.webservices.zpg.co.uk/sandbox/v1/listing/list

C# web request has error

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.DefaultConnectionLimit = 9999;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3| SecurityProtocolType.Tls12; 

        string certificateText = File.ReadAllText(@"D:\public.crt");
        string privateKeyText = File.ReadAllText(@"D:\private.pem");
        ICertificateProvider provider = new CertificateFromFileProvider(certificateText, privateKeyText);
        X509Certificate2 clientCertificate = provider.Certificate;

        var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://realtime-listings-api.webservices.zpg.co.uk/sandbox/v1/listing/list");
        httpWebRequest.ContentType = "application/json; profile=https://realtime-listings.webservices.zpg.co.uk/docs/v1.2/schemas/listing/list.json";
        httpWebRequest.Method = "POST";
        httpWebRequest.ClientCertificates.Add(clientCertificate);

        ServicePointManager.ServerCertificateValidationCallback +=new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) =>{return true;});

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = "{\"branch_reference\":\"123\"}";
            streamWriter.Write(json);
            streamWriter.Flush();
        }

        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            var result = streamReader.ReadToEnd();
        }

Error Detail:

The request was aborted: Could not create SSL/TLS secure channel.

error in below line

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

Any one can help on this?

</div> </div>


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>