• utilize HttpClient to generate a SSL access and generate REST access to fetch data, async programming? cool and brief


    WebRequestHandler handler = new WebRequestHandler();
                    try
                    {
                        X509Certificate2 certificate = new X509Certificate2(System.IO.File.ReadAllBytes(ConfigurationManager.AppSettings["webapicertpath"]), ConfigurationManager.AppSettings["webapicertpwd"]); ;
                        handler.ClientCertificates.Add(certificate);
                        ServicePointManager.ServerCertificateValidationCallback =
                            (object sender, X509Certificate certificate1, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
                            {
                                return true;
                            };
                    }
                    catch
                    {
                    }
                    httpClient = new HttpClient(handler);
    

      to fetch data with REST httpclient, just utilize code below:

                    case "get":
                        result = httpClient.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                        break;
                    case "post":
                        result = httpClient.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
                        break;
                    case "put":
                        result = httpClient.PutAsync(url, content).Result.Content.ReadAsStringAsync().Result;
                        break;
                    case "delete":
                        result = httpClient.DeleteAsync(url).Result.Content.ReadAsStringAsync().Result;
                        break;
                    default:
                        break;
    

      

  • 相关阅读:
    机器学习数学符号解释
    JVM Guide
    Mysql优化
    JAVA必会算法--冒泡排序
    HashMap-JDK源码阅读
    vue 下载文件
    CommonMethod
    log4net 写日志
    WebAPI 封装返回值
    二, .NET Core 微服务学习 ——集中式代理-Nginx
  • 原文地址:https://www.cnblogs.com/hualiu0/p/5133357.html
Copyright © 2020-2023  润新知