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

  • 相关阅读:
    webpack 3.x loader
    git忽略已经被提交的文件,以及如何恢复追踪
    sessionstorage:本地临时存储
    es6中顶层对象属性≠全局属性
    Android DRM
    FFMPEG中关于ts流的时长估计的实现
    整理mp4协议重点,将协议读薄
    LOCAL_SHARED_LIBRARIES 与 LOCAL_LDLIBS,LOCAL_LDFLAGS的区别
    valgrind调查内存leak
    Android中*_handle_t/ANativeWindowBuffer/ANativeWindow/GraphicBuffer/Surface的关系
  • 原文地址:https://www.cnblogs.com/rengke2002/p/7661903.html
Copyright © 2011-2022 走看看