C#中如何设置使用代理IP发送网络请求?作者:数据无忧 时间:2020-09-18 13:24:53 |
C#中实现用代理IP连接网络很简单,主要是通过修改本地注册表实现功能,代码如下 // 设置代理IP,参数ip的格式为是 ip:port private void setProxy(string ip) { Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software/Microsoft/Windows/CurrentVersion/Internet Settings", true); //设置代理可用 rk.SetValue("ProxyEnable", 1); //设置代理IP和端口 rk.SetValue("ProxyServer", ip); rk.Close(); } // 取消本地的代理IP private void disProxy() { Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software/Microsoft/Windows/CurrentVersion/Internet Settings", true); //设置代理可用 rk.SetValue("ProxyEnable", 0); //设置代理IP和端口 rk.SetValue("ProxyServer", ""); rk.Close(); } |