c# HttpWebRequest使用Proxy实现指定IP的代理

内网用户或代理上网的用户使用

HttpWebRequest request (HttpWebRequest)WebRequest.Create("http://www.example.com/Default.aspx");
System.Net.WebProxy proxy = new WebProxy("127.0.0.1", 8000);//指定的ip和端口
request.Proxy = proxy;
using (WebResponse response = request.GetResponse())
{
    using (TextReader reader = new StreamReader(response.GetResponseStream()))
    {
         string line;
         while ((line = reader.ReadLine()) != null)
         Console.WriteLine(line);
    }
}

 

你可能感兴趣的:(C#开发)