zoukankan      html  css  js  c++  java
  • 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);
                }
            }
  • 相关阅读:
    FFT入门
    FJOI省队集训 chessboard
    FJOI省队集训 florida
    树上莫队
    NOIP2015 Revenge
    APIO2013 tasksauthor
    油漆门
    一些字符串有关的题目
    字符串题模板集合
    sg函数与博弈论2
  • 原文地址:https://www.cnblogs.com/bimingsong/p/5663851.html
Copyright © 2011-2022 走看看