码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-01-15 16:12:18      阅读:189      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!