How to authenticate with Rest-client based on HttpClient and .net4

后端 未结 8 1082
失恋的感觉
失恋的感觉 2020-12-13 17:33

Been elaborating a bit with HttpClient for building a rest client. But I can\'t figure out, nor find any examples on how to authenticate towards the server. Most likely I wi

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 18:23

    All these are out of date. The final way to do it is as follows:

    var credentials = new NetworkCredential(userName, password);
    var handler = new HttpClientHandler { Credentials = credentials };
    
    using (var http = new HttpClient(handler))
    {
        // ...
    }
    

提交回复
热议问题