南京网站建设网站,500个短视频素材免费,苏州市网站建设培训,公司网站 seo百度#xff0c;google加自己理解后#xff0c;将所得方法总结一下#xff1a; 方法1#xff1a;修改注册表Software//Microsoft//Windows//CurrentVersion//Internet Settings下 ProxyEnable和ProxyServer。这种方法适用于局域网用户#xff0c;拨号用户无效。 1p…百度google加自己理解后将所得方法总结一下 方法1修改注册表Software//Microsoft//Windows//CurrentVersion//Internet Settings下 ProxyEnable和ProxyServer。这种方法适用于局域网用户拨号用户无效。 1 public partial class Form1 : Form 2 { 3 4 //用于刷新注册表 5 [DllImport(wininet, 6 SetLastError true, 7 CharSet CharSet.Auto, 8 EntryPoint InternetSetOption, 9 CallingConvention CallingConvention.StdCall)]101112 public static extern bool InternetSetOption13 (14 int hInternet,15 int dmOption,16 IntPtr lpBuffer,17 int dwBufferLength18 );1920 private void btnStart_Click(object sender, EventArgs e)21 {22 RegistryKey pregkey;23 pregkey Registry.CurrentUser.OpenSubKey(Software//Microsoft//Windows//CurrentVersion//Internet Settings, true);24 if (pregkey null)25 {26 Console.WriteLine(键值不存在);27 }28 else29 {30 pregkey.SetValue(ProxyEnable, 1);31 pregkey.SetValue(ProxyServer, 代理地址);32 //激活代理设置33 InternetSetOption(0, 39, IntPtr.Zero, 0);34 InternetSetOption(0, 37, IntPtr.Zero, 0);35 webBrowser1.Navigate(txtweb.Text, false);36 // System.Threading.Thread.Sleep(10000);37 }38 }39}方法2 修改注册表
Software//Microsoft//Windows//CurrentVersion//Internet Settings//Connections下以你拨号连接名为键的值该键为二进制。这种方法适用于拨号用户。public partial class FrmMain : Form {[DllImport(wininet, SetLastError true, CharSet CharSet.Auto, EntryPoint InternetSetOption, CallingConvention CallingConvention.StdCall)] public static extern bool InternetSetOption ( int hInternet, int dmOption, IntPtr lpBuffer, int dwBufferLength );//将值转换为注册表中的二进制值public byte ChangeTobyte(char i) { byte key 0; switch (i) { case 0: key 48; break; case 1: key 49; break; case 2: key 50; break; case 3: key 51; break; case 4: key 52; break; case 5: key 53; break; case 6: key 54; break; case 7: key 55; break; case 8: key 56; break; case 9: key 57; break; case .: key 46; break; case :: key 58; break; } return key; }private void btnStart_Click(object sender, EventArgs e) { int i (代理地址).Length; byte[] key new byte[50]; char[] source (代理地址).ToCharArray(); key[0] 60; key[4] 3; key[8] 3; key[12] (byte)i; for (int ii 0; ii source.Length; ii) { key[16 ii] ChangeTobyte(source[ii]); } string sDirectX ; for (int k 0; k key.Length; k) { if (key[k] ! 0) { sDirectX key[k] ; } } //MessageBox.Show(sDirectX); RegistryKey pregkey; pregkey Registry.CurrentUser.OpenSubKey(Software//Microsoft//Windows//CurrentVersion//Internet Settings//Connections, true); if (pregkey null) { Console.WriteLine(键值不存在); } else { pregkey.SetValue(拨号名字对应键值, key, RegistryValueKind.Binary); //激活代理设置 InternetSetOption(0, 39, IntPtr.Zero, 0); InternetSetOption(0, 37, IntPtr.Zero, 0); webBrowser1.Navigate(txtweb.Text, false); webBrowser1.Refresh(); } }}方法3 使用c#自带的
webproxy类使用这种方法可以获得目标网站的响应但我不会把这种响应用IE反馈出来有高手帮个忙么
网上的代码说是MSDN的HttpWebRequest myWebRequest(HttpWebRequest)WebRequest.Create(
http://www.microsoft.com/); WebProxy myProxynew WebProxy(); // Obtain the Proxy of the Default browser. myProxy(WebProxy)myWebRequest.Proxy; 这行我编译不通过 // Print the Proxy Url to the console. Console.WriteLine(/nThe actual default Proxy settings are {0},myProxy.Address); try { Console.WriteLine(/nPlease enter the new Proxy Address that is to be set:); Console.WriteLine((Example:
http://myproxy.example.com:port/)); string proxyAddress; proxyAddress Console.ReadLine(); if(proxyAddress.Length0) { Console.WriteLine(/nPlease enter the Credentials ); Console.WriteLine(Username:); string username; username Console.ReadLine(); Console.WriteLine(/nPassword:); string password; password Console.ReadLine(); // Create a new Uri object. Uri newUrinew Uri(proxyAddress); // Associate the newUri object to myProxy object so that new myProxy settings can be set. myProxy.AddressnewUri; // Create a NetworkCredential object and associate it with the Proxy property of request object. myProxy.Credentialsnew NetworkCredential(username,password); myWebRequest.ProxymyProxy; } Console.WriteLine(/nThe Address of the new Proxy settings are {0},myProxy.Address); HttpWebResponse myWebResponse(HttpWebResponse)myWebRequest.GetResponse(); 我改了下HttpWebRequest myWebRequest (HttpWebRequest)WebRequest.Create(http://www.123cha.com); WebProxy myProxy new WebProxy(代理地址, true); try { Console.WriteLine(/nThe Address of the new Proxy settings are {0}, myProxy.Address); HttpWebResponse myWebResponse (HttpWebResponse)myWebRequest.GetResponse(); webBrowser1.DocumentStream myWebResponse.GetResponseStream(); } catch { }