[C#] 纯文本查看 复制代码 public static string SendInfoServer(string postdata)
{
//创建Httphelper对象
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = baseUrl+requestUrl,//URL 必需项
Method = "post",//URL 可选项 默认为Get
//ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
ContentType = contentType,//返回类型 可选项有默认值
PostDataType = PostDataType,//默认为字符串,同时支持Byte和文件方法
PostEncoding = System.Text.Encoding.UTF8,//默认为Default,
Postdata = postdata,//Post要发送的数据
};
if (PostdataByte != null)
{
item.PostdataByte = PostdataByte;
}
if (GlobalUserClass.GlobalAccessToken != "")
{
item.Header.Add("ac", "Bearer " + GlobalUserClass.GlobalAccessToken);
}
HttpResult result = http.GetHtml(item);
string access_token = result.Html;
//开始异步调用
//http.BeginInvokeGetHtml(item, new ResultHandler(SetInvokeHtml));
return access_token;
}
我用的是HttpHelper ,不是HttpWebReques,我查了HttpHelper 的API,但没有ClientCertificates这个方法,那我怎么为上述代码中的HttpHelper 加上无视证书的功能呀?
[C#] 纯文本查看 复制代码 //这一句一定要写在创建连接的前面。使用回调的方法进行证书验证。
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
// 与指定URL创建HTTP请求
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
//创建证书文件
X509Certificate objx509 = new X509Certificate(Application.StartupPath + "\\123.cer");
//添加到请求里
request.ClientCertificates.Add(objx509);
|