可以参考https://www.cnblogs.com/ccsharp/p/3270344.html

和https://blog.csdn.net/baidu_27474941/article/details/52484395

public static bool checkvalidationresult(object sender, system.security.cryptography.x509certificates.x509certificate certificate, x509chain chain, sslpolicyerrors errors)

{ return true; }

//通过https协议上传数据,url为接口地址,str为要上传的数据

public static string httppost(string url,string str)

{

string result=””;

try

{

 

servicepointmanager.expect100continue = false;

servicepointmanager.securityprotocol = securityprotocoltype.tls11|securityprotocoltype.tls12|securityprotocoltype.tls|securityprotocoltype.ssl3;// 只有.net4.5以上才有tls11,tls12,建立通道

servicepointmanager.servercertificatevalidationcallback = new remotecertificatevalidationcallback(checkvalidationresult);

httpwebrequest req=(httpwebrequest )webrequest.create(url) ;

//读取本地计算机证书

x509store certstore = new x509store(storename.my, storelocation.localmachine);
certstore.open(openflags.readonly);
x509certificate2collection certcollection = certstore.certificates.find(x509findtype.findbysubjectname, “安装的证书名字”, false);
req.clientcertificates.add(certcollection[0]));

//传输数据

req.method = “post”;
req.contenttype = “application/json”;//根据编码格式进行选择
req.contentlength = data.length;

byte[] data=encoding.utf8.getbytes(str);//数据类型转换
using (var reqstream = request.getrequeststream())
{
reqstream .write(data, 0, data.length);

reqstream .close();
}

httpwebresponse response = (httpwebresponse)request.getresponse();

stream stream=response.getresponsestream();
using(stream reader=new streamreader(stream,encoding.utf8))

{

result=reader.readtoend();

}

}

catch

{

throw;

}

return result;

}

 

https传输证书授权问题

一、导入证书 

1. 单击 开始 ,单击 运行 ,键入 mmc ,然后单击 确定 。

2. 在 文件 菜单上单击 添加/删除管理单元 。

3. 在 可用的管理单元 列表中选择 证书 ,点击 添加 。

4. 在 证书管理 对话框中选择 计算机账户 ,然后单击 下一步

5. 在 选择计算机 对话框中,单击 完成 。

6. 在 添加或删除管理单元 对话框单击 确定 。

7. 展开 证书 (本地计算机) ,展开 个人 ,然后单击 证书

8. 右键 -》 所有任务-》导入 选择你的证书导入

9.展开“受信任的根证书颁发机构”,选择证书–所有任务–导入

. 修改iis上对应项目的程序池标识(如果是服务端,客户端的不用此步骤)

1. 打开iis -> 选择[应用程序池] -> 选中对应的项目 -> 选择右侧的[高级设置]

2. 找到[进程模型] -> 修改[标识]属性值

3. applicationpoolidentity 修改为 networkservice

、安装授权工具

 1.下载 winhttpcertcfg.exe 安装

 附下载地址:1.https://www.microsoft.com/en-us/download/confirmation.aspx?id=19801

 2.https://www.microsoft.com/en-us/download/details.aspx?id=19801

 3.安装完  用命令窗口  跳转到 c:\program files (x86)\windows resource kits\tools(安装的路径) 执行

winhttpcertcfg -g -c local_machine\my -s test-a “networkservice”

test是证书名,不带后缀,替换成你的证书名字就行

详细信息可以参考https://www.cnblogs.com/ccsharp/p/3270344.html

 

四、设置网站ssl

选中网站,点击 ssl设置 ,选择要求ssl,选择必须,点击应用