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

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;

  

时间: 2024-10-12 03:26:59

utilize HttpClient to generate a SSL access and generate REST access to fetch data的相关文章

Access之C#连接Access

原文:Access之C#连接Access 如果是个人用的小程序的话.一般都推荐用Sqlite和Access 使用SQlite数据库需要安装SQLite驱动,详情:SQLite之C#连接SQLite 同样要使用Access数据库一必须安装Access驱动程序.驱动下载:http://pan.baidu.com/s/1moWje 官网下载:http://www.microsoft.com/zh-cn/download/details.aspx?id=13255 可以在收索你需要的版本. 微软ADO.

Role-based Access Control vs Attribute-based Access Control: How to Choose

https://www.ekransystem.com/en/blog/rbac-vs-abac Access control is a fundamental element of the security infrastructure of any company. Every security officer wants to apply the principle of less privilege, zero-trust, segregation of duties, and othe

You may experience an access violation when you access an STL object through a pointer or reference in a different DLL or EXE

Symptoms When accessing an STL object created in one DLL or EXE through a pointer or reference in a different DLL or EXE, you may experience an access violation or other serious program errors including the appearance of data corruption or data loss.

Next Instruction Access Intent Instruction

Executing a Next Instruction Access Intent instruction by a computer. The processor obtains an access intent instruction indicating an access intent. The access intent is associated with an operand of a next sequential instruction. The access intent

关于 C# HttpClient的 请求

Efficiently Streaming Large HTTP Responses With HttpClient Downloading large files with HttpClient and you see that it takes lots of memory space? This post is probably for you. Let's see how to efficiently streaming large HTTP responses with HttpCli

Oracle Applications Multiple Organizations Access Control for Custom Code

文档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code Checked for relevance on 12-JAN-2011 See Change Record This document discusses how to update the customization code that is affected by the access co

Heterogeneous Self-Organizing Network for Access and Backhaul

This application discloses methods for creating self-organizing networks implemented on heterogeneous mesh networks. The self-organizing networks can include a computing cloud component coupled to the heterogeneous mesh network. In the methods and co

Access Toke调用受保护的API

ASP.NET Web API与Owin OAuth:使用Access Toke调用受保护的API 在前一篇博文中,我们使用OAuth的Client Credential Grant授权方式,在服务端通过CNBlogsAuthorizationServerProvider(Authorization Server的一个实现)成功发放了Access Token,并在客户端成功拿到了Access Token. 那Access Token有什么用呢?在OAuth中对Resource Server(比如

ASP.NET Web API与Owin OAuth:使用Access Toke调用受保护的API

在前一篇博文中,我们使用OAuth的Client Credential Grant授权方式,在服务端通过CNBlogsAuthorizationServerProvider(Authorization Server的一个实现)成功发放了Access Token,并在客户端成功拿到了Access Token. 那Access Token有什么用呢?在OAuth中对Resource Server(比如Web API)访问权限的验证都是基于Access Token.不管是什么样的客户端来调用,Reso