Consume RESt API from .NET

前端 未结 4 987
天涯浪人
天涯浪人 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:13

    Just to add a bit of value to this thread (I too was looking for a way to consume a RESTful service and easily provide credentials and came across this thread ... I did not have the "Date" requirement), Aaron Skonnard has written an excellent article on using the WCF REST Starter Kit called:

    A Developer's Guide to the WCF REST Starter Kit

    There is a very informative section on how to consume a RESTful service using HttpClient. And here's the code snippet to talk to Twitter:

    HttpClient http = new HttpClient("http://twitter.com/statuses/");
    http.TransportSettings.Credentials =
        new NetworkCredential("{username}", "{password}");
    HttpResponseMessage resp = http.Get("friends_timeline.xml");
    resp.EnsureStatusIsSuccessful();
    ProcessStatuses(resp.Content.ReadAsStream());
    

提交回复
热议问题