使用来自.NET REST API [英] Consume RESt API from .NET
问题描述
我想从我的.NET应用程序消耗的REST API。这个API的都用JAVA写的。 我问过相的HTTP头的认证证书。我如何可以通过如DATE,授权和接受通过HTTP标头,这些认证证书。
I am trying to consume REST API from my .NET Application. This API's are all written in JAVA. I am asked to pass the authentication credentials vis HTTP headers. How can I pass these authentication credentials like 'DATE', 'AUTHORIZATION' and 'Accept' via HTTP headers.
哪个类.NET我可以用它来完成这个任务。谁能帮我这个?
Which class in .NET can I use to accomplish this task. Can anyone help me with this?
您的帮助将是AP preciated。
All your help will be appreciated.
Ajish。
推荐答案
更新
本库现在已经换成 http://nuget.org/packages /Microsoft.Net.Http/2.1.10
使用的Microsoft.Http客户端库,在 WCF REST入门包preVIEW 2 。
Use the Microsoft.Http client library that is in WCF REST Starter Kit Preview 2.
下面是如何,你可以使用它:
Here is how you could use it:
var client = new HttpClient();
client.DefaultHeaders.Authorization = new Credential("ArbitraryAuthHeader");
client.DefaultHeaders.Date = DateTime.Now;
client.DefaultHeaders.Accept.Add("application/xml");
var response = client.Get("http://example.org");
var xmlString = response.Content.ReadAsString();
这篇关于使用来自.NET REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!