public static void ProcessRequest()
{
//类似浏览器确认证书合法方法的绑定
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://aaaaaa.com/getToken?");

string param = "userName=abc&type=123";
byte[] bs = Encoding.UTF8.GetBytes(param);

request.Method = "post";
using (Stream reqStram = request.GetRequestStream())
{
reqStram.Write(bs, 0, bs.Length);
}
string strResponse = "";
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}

Console.ReadKey();
}
//该方法用于验证服务器证书是否合法,当然可以直接返回true来表示验证永远通过。服务器证书具体内容在参数certificate中。可根据个人需求验证
//该方法在request.GetResponse()时触发
private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
//为了通过证书验证,总是返回true
return true;
}

net 调用https接口的更多相关文章

  1. delphi调用https接口

    delphi调用http接口直接使用idhttp就可以了,但是调用https接口的时候就需要和IdSSLIOHandlerSocket1控件一起使用. 截图中是两个控件的具体配置,需要注意的是IdSS ...

  2. JAVA 调用https接口, java.security.cert.CertificateException

    package com.easycare.store.util; import java.security.cert.CertificateException; import java.securit ...

  3. 【IoT平台北向API调用】使用Postman调用Https接口

    1. Download and install postman https://www.getpostman.com/ Version:the version I download is Postma ...

  4. 用curl调用https接口

    今天在windows下用curl类获取微信token一直返回false,查阅资料后,发现是https证书的锅,在curl类中加上这两条,问题瞬间解决. curl_setopt($ch, CURLOPT ...

  5. Java调用HTTPS接口的证书配置

    首先需要获取到证书文件. 然后,将证书导入到本地: keytool -import -noprompt -trustcacerts -alias <AliasName> -file < ...

  6. Java调用Http/Https接口(7,end)--WebClient调用Http/Https接口

    WebClient是Spring提供的非阻塞.响应式的Http客户端,提供同步及异步的API,将会代替RestTemplate及AsyncRestTemplate.文中所使用到的软件版本:Java 1 ...

  7. Java调用Http/Https接口(6)--RestTemplate调用Http/Https接口

    RestTemplate是Spring提供的用于访问Http接口的客户端,提供同步的API:在将来的Spring版本中可能会过时,将逐渐被WebClient替代.文中所使用到的软件版本:Java 1. ...

  8. Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口

    HttpAsyncClient是HttpClient的异步版本,提供异步调用的api.文中所使用到的软件版本:Java 1.8.0_191.HttpClient 4.1.4. 1.服务端 参见Java ...

  9. Java调用Http/Https接口(4)--HttpClient调用Http/Https接口

    HttpClient是Apache HttpComponents项目下的一个组件,是Commons-HttpClient的升级版,两者api调用写法也很类似.文中所使用到的软件版本:Java 1.8. ...

随机推荐

  1. VMware 虚拟机桥接网络设置

    一.桥接的基本原理    配置成桥接网络连接模式的虚拟机就当作主机所在以太网的一部分,虚拟系统和宿主机器的关系,就像连接在同一个Hub上的两台电脑,可以像主机一样可以访问以太网中的所有共享资源和网络连 ...

  2. Linux如何查看进程、杀死进程、启动进程等常用命令

    Linux如何查看进程.杀死进程.启动进程等常用命令 关键字: linux 查进程.杀进程.起进程1.查进程    ps命令查找与进程相关的PID号:    ps a 显示现行终端机下的所有程序,包括 ...

  3. Replace Pioneer 注册

    批量文本替换工具,Replace Pioneer 注册:http://www.mind-pioneer.com

  4. Gate level Simulation(门级仿真)

    1 什么是后仿真? 后仿真也成为时序仿真,门级仿真,在芯片布局布线后将时序文件SDF反标到网标文件上,针对带有时序信息的网标仿真称为后仿真. 2 后仿真是用来干嘛的? 检查电路中的timing vio ...

  5. HTML DOM Element

    HTML DOM Element(元素) 文档本身是文档节点 . 所有 HTML 元素是元素节点 . 所有 HTML 属性是属性节点 HTML 元素内的文本是文本节点 . 注释是注释节点 . NODE ...

  6. Python 无限循环

    import threading import time class CountDownTimer(threading.Thread): def __init__(self, seconds, act ...

  7. 一般处理程序中使用session

    首先引用:using System.Web.SessionState;  再在 IHttpHandler 后面加逗号加IReadOnlySessionState:IHttpHandler,IReadO ...

  8. MVC数据传递和多表单

    1.数据传递(1)session和TempData 全局变量,可以将值从一个动作传递到另一个动作,也可以从控制层传递到视图层. TempData取一遍值后自动销毁. session使用: //控制器中 ...

  9. Android菜鸟成长记9 -- selector的用法

    在项目开发的时候,由于系统给出的控件不够美观,因此开发时领导常常要我更改下界面,用美工给的图片取代系统图片.开始时,我只是给按钮等设置一下背景图片,这样做虽然美观了,但界面看起来却比较死板,比如用户点 ...

  10. 新年PR交期回写,展望期由14天改为30天,FP_PR2SAP ;转单量改为100W;FP_PR2SAP_MOD_NEW