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

  • 相关阅读:
    Introduction to debugging neural networks
    Faster R-CNN教程
    最长递增子序列
    321. Create Maximum Number 解题方法详解
    Ubuntu安装opencv with cuda
    转载:LeetCode:5Longest Palindromic Substring 最长回文子串
    64. Minimum Path Sum
    322. Coin Change
    148. Sort List
    微信浏览器禁止页面下拉查看网址(不影响页面内部scroll)
  • 原文地址:https://www.cnblogs.com/rengke2002/p/7661903.html
Copyright © 2020-2023  润新知