zoukankan      html  css  js  c++  java
  • HttpClient证书回调问题解决

    /// <summary>
            /// httpclient请求
            /// </summary>
            /// <param name="client"></param>
            /// <param name="url"></param>
            /// <param name="mobile"></param>
            /// <param name="content"></param>
            /// <returns></returns>
            public string HttpRequest(HttpClient client, string url, string mobile, string content)
            {
                var req = new HttpRequestMessage();
                req.Headers.Clear();
                req.Headers.Add("ContentType", "application/x-www-form-urlencoded;charset=utf-8");
                req.Method = HttpMethod.Post;
                Dictionary<string, string> paras = new Dictionary<string, string>();
                paras.Add("action", "send");
                paras.Add("account", this.config.Account.UserName);
                paras.Add("password", this.config.Account.Password);
                paras.Add("mobile", mobile);
                paras.Add("content", content);
                req.Content = new FormUrlEncodedContent(paras);
                req.RequestUri = new Uri(url);
                ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
                var response = client.SendAsync(req).Result;
                try
                {
                    response.EnsureSuccessStatusCode();
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error:{0}", ex.Message);
                    return "";
                }
                return response.Content.ReadAsStringAsync().Result;
            }
            private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            {
                return true;
            }

  • 相关阅读:
    8天学通MongoDB——第三天 细说高级操作
    8天学通MongoDB——第二天 细说增删查改
    8天学通MongoDB——第一天 基础入门
    Redis Web界面管理工具
    Redis 起步
    使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件
    面试应该如何面?
    Login oracle for external authenticate
    突然发现我脾气变好了
    一种持续构建构想
  • 原文地址:https://www.cnblogs.com/rengke2002/p/7661903.html
Copyright © 2011-2022 走看看