HttpClient设置代理

        static void Main(string[] args)
        {

            Console.WriteLine("In main before call to GetData!");
            GetData();
            Console.WriteLine("Back in main after call to GetData!");
            Console.ReadKey();
        }
        private static async void GetData()
        {
            WebProxy proxy = new WebProxy();
            proxy.Address = new Uri("http://localhost:8080");  //代理地址
            proxy.Credentials = new NetworkCredential("user", "pass");
            HttpClientHandler handler = new HttpClientHandler();
            handler.Proxy = proxy;
            HttpClient httpClient = new HttpClient(handler);
            HttpResponseMessage response = null;
            response = await httpClient.GetAsync("http://www.cnblogs.com");
            if(response.IsSuccessStatusCode)
            {
                Console.WriteLine("Response Status Code and Reason Phrase:{0} {1}", response.StatusCode, response.ReasonPhrase);
                string responseBodyAsText = response.Content.ReadAsStringAsync().Result;
                Console.WriteLine(responseBodyAsText);
            }
        }
原文地址:https://www.cnblogs.com/bimingsong/p/5663851.html