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