首页 > 数据库技术 > 详细

utilize HttpClient to generate a SSL access and generate REST access to fetch data

时间:2016-01-15 16:09:55      阅读:210      评论:0      收藏:0      [点我收藏+]
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;

  

utilize HttpClient to generate a SSL access and generate REST access to fetch data

原文:http://www.cnblogs.com/hualiu0/p/5133357.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!