Proxy Basic Authentication in C#: HTTP 407 error

后端 未结 6 1974
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 05:18

I am working with a proxy that requires authentication, i.e., in a browser if I try to open a page it will immediately ask for credentials. I supplied same credentials in my

6条回答
  •  遥遥无期
    2020-11-28 05:52

    You can use like this, it works!

            WebProxy proxy = new WebProxy
            {
                Address = new Uri(""),
                Credentials = new NetworkCredential("", "")
            };
    
            HttpClientHandler httpClientHandler = new HttpClientHandler
            {
                Proxy = proxy,
                UseProxy = true
            };
    
            HttpClient client = new HttpClient(httpClientHandler);
    
            HttpResponseMessage response = await client.PostAsync("...");
    

提交回复
热议问题