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;
            }

  • 相关阅读:
    [网络流24题]飞行员配对方案问题
    学习笔记——线性基
    HDU 4507 吉哥系列故事——恨7不成妻(数位DP求平方和)
    bzoj1415&洛谷P4206 [NOI2005]聪聪与可可
    后缀自动机(模板+例题)
    最小表示法(模板)poj1059
    求次小生成树(洛谷P4180&bzoj1977)
    KMP poj3942
    最小表示法(模板) CH1807
    数位dp 求山峰数(hill)
  • 原文地址:https://www.cnblogs.com/rengke2002/p/7661903.html
Copyright © 2011-2022 走看看