How to get HttpClient to pass credentials along with the request?

前端 未结 7 1734
南笙
南笙 2020-11-22 14:52

I have a web application (hosted in IIS) that talks to a Windows service. The Windows service is using the ASP.Net MVC Web API (self-hosted), and so can be communicated with

7条回答
  •  再見小時候
    2020-11-22 15:44

    It worked for me after I set up a user with internet access in the Windows service.

    In my code:

    HttpClientHandler handler = new HttpClientHandler();
    handler.Proxy = System.Net.WebRequest.DefaultWebProxy;
    handler.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
    .....
    HttpClient httpClient = new HttpClient(handler)
    .... 
    

提交回复
热议问题