Consume RESt API from .NET

前端 未结 4 932
天涯浪人
天涯浪人 2021-01-31 06:16

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

4条回答
  •  借酒劲吻你
    2021-01-31 07:23

    Update

    This library has now been replaced by http://nuget.org/packages/Microsoft.Net.Http/2.1.10


    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();
    

提交回复
热议问题