C# 使用SSL访问webservice(自用)

xiaoxiao2021-02-28  72

{

ServicePointManager.ServerCertificateValidationCallback= new RemoteCertificateValidationCallback((a, b, c, d) => { return true; });//表示不对服务端证书进行有效性校验

SSLWebService sws = new SSLWebService();

ws.ClientCertificates.Add(X509Certificate.CreateFromCertFile(Path.GetFullPath(@"../../") + @"Resourcescerfile.cer"));

sws.DoSomeThing(“Hello World!”);

}

{

string reqUrl = "";

/// 构建请求的HttpWebRequest对象

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(reqUrl);        req.KeepAlive = true;

/// 从本地文件中加载证书        req.ClientCertificates.Add(X509Certificate.CreateFromCertFile(ConfigurationManager.AppSettings["CertFilePath"]));        string requestValue = "<request><ver>版本0.1</ver></request>";        byte[] requestData = Encoding.UTF8.GetBytes(requestValue);

req.Method = "POST";        req.ContentType = "application/x-www-form-urlencoded;charset=UTF8";        req.ContentLength = requestData.Length;

}

转载请注明原文地址: https://www.6miu.com/read-55258.html

最新回复(0)