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. PAT 乙级 1005. 继续(3n+1)猜想 (25)

    1005. 继续(3n+1)猜想 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B   卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情 ...

  2. KBMMW 4.92.00 发布

    We are happy to announce the release of kbmMW Professional and Enterprise Edition. Yet again kbmMW c ...

  3. leetCode 354. Russian Doll Envelopes

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

  4. VC++ 两种动态调整控件位置的方法(CButton设置为Radio形式会出现错误)

    ((CButton*)GetDlgItem(IDC_CHECK1))->MoveWindow(, cy - , , ); ((CButton*)GetDlgItem(IDC_CHECK2))-& ...

  5. Elasticsearch相关资源

    安装介绍 http://www.doc88.com/p-171165797348.html 入门教程 http://www.iteye.com/blogs/subjects/elasticsearch ...

  6. Python Microsoft Visual C++ Compiler Package for Python 2.7

    错误描述: 在从源代码安装Python模块时遇到此错误.可是我明明从官网下载并安装了Microsoft Visual C++ Compiler Package for Python 2.7,且配置了环 ...

  7. C# 解析JSON格式数据

    JSON简介 JSON(全称为JavaScript ObjectNotation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集.JSON采用完全独立于语言的文本格式,可 ...

  8. Python—函数的参数组合

    参数组合 在Python中定义函数,可以用必选参数.默认参数.可变参数.关键字参数和命名关键字参数,这5种参数都可以组合使用.但是请注意,参数定义的顺序必须是:必选参数.默认参数.可变参数.命名关键字 ...

  9. LVS简单实现NAT&DR模型

    LVS:Linux Virtual Server  一个由章文嵩博士发起的自由软件项目,它的官方站点是www.linuxvirtualserver.org. 现在LVS已经是Linux标准内核的一部分 ...

  10. iOS Core Animation之CALayer心得

    使用CALayer的mask实现注水动画效果 Core Animation一直是iOS比较有意思的一个主题,使用Core Animation可以实现非常平滑的炫酷动画.Core animtion的AP ...