Skip to content
Snippets Groups Projects

更新corpcore中的https请求

Merged 刘圳 requested to merge feature/liuzhen into develop
Compare and
1 file
+ 14
0
Compare changes
  • Side-by-side
  • Inline
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Web;
namespace WeChat.CorpLib.Core
@@ -20,6 +22,8 @@ namespace WeChat.CorpLib.Core
public static string PostRequest(string url, DataTypeEnum ContentType, string strData)
{
string result = string.Empty;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
WebRequest webRequest = WebRequest.Create(url);
webRequest.Method = MethodTypeEnum.Post.ToString();
webRequest.ContentType = "application/" + ContentType.ToString();
@@ -45,6 +49,8 @@ namespace WeChat.CorpLib.Core
public static string GetRequest(string url)
{
string result = string.Empty;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
WebRequest webRequest = WebRequest.Create(url);
webRequest.Method =MethodTypeEnum.Get.ToString();
using (StreamReader reader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
@@ -53,8 +59,16 @@ namespace WeChat.CorpLib.Core
}
return result;
}
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // 总是接受 认证平台 服务器的证书
return true;
}
}
/// <summary>
/// 带参数据类型
/// </summary>