下面的curl请求工作正常,但是当我在C#Web请求中转换此请求时,出现错误。我正在使用.net 4.6桌面应用程序。
卷曲请求工作正常:
curl --key private.pem --cert public.crt --data“ {\” branch_reference \“:\” 123 \“}” --header“内容类型: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请求有错误
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = 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();
}
错误详细信息: 请求已中止:无法创建SSL / TLS安全通道。
下面一行错误
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();