The implementation form of the HTTP proxy can be achieved by modifying the registry key and then starting the browser. You can also construct an HTTP header Through socket communication. The following describes how to implement the registry.
To implement the registry, you only need to modify several key registry keys.
Item 1: Enable the proxy registry.
Item 2: proxy IP address and port.
Item 3: connection method.
Item 4: Make the registry entry take effect immediately. Strictly speaking, this step does not modify the registry key, but calls an API to notify the registry key to take effect.
The following code is used:
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. runtime. interopservices; using system. diagnostics; using Microsoft. win32; namespace utilsp. classlib {public class proxysp {[dllimport ("wininet. DLL ", setlasterror = true)] Private Static extern bool internetsetoption (intptr hinternet, int dwoption, intptr lpbuffer, int lpdwbufferlength); Private const int in Ternet_option_refresh = 37; private const int internet_option_proxy = 38; private const int timeout = 39; private const int internet_open_type_proxy = 3; private const int internet_open_type_direct = 1; # region changeuseragent function public static void changeuseragent () {var appname = process. getcurrentprocess (). mainmodule. modulename; regeditsp. write (@ "hkey_local_machin E \ Software \ Microsoft \ Internet Explorer \ main \ featurecontrol \ feature_browser_emulation ", appname, 9999, registryvaluekind. DWORD) ;}# endregion # region setproxyenabled function // <summary> // set proxy. /// </Summary> /// <Param name = "isproxyenabled"> true: is enabled. false: is not enabled. </param> // <Param name = "proxyip"> proxy IP and port. format: 192.168.100.162: 8080 </param> // <returns> </returns> Public static bool setproxy (bool isproxyenabled, string proxyip = "") {string regpath = "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Internet Settings "; // enabled proxy option. bool issetproxyenabledok = regeditsp. write (regeditsp. regedit_root_set.hkey_current_user, regpath, "proxyenable", isproxyenabled? 1: 0, true); bool issetproxyip = true; If (! String. isnullorempty (proxyip) {issetproxyip = regeditsp. write (regeditsp. regedit_root_set.hkey_current_user, regpath, "proxyserver", proxyip, true);} bool isconnectionok = setconnection (isproxyenabled, proxyip); bool isnotifyok = internetsetoption (intptr. zero, internet_option_settings_changed, intptr. zero, 0); // your y proxy in the Regedit has changed. lanuch proxy when connect next. bool isreadok = Internetsetoption (intptr. zero, internet_option_refresh, intptr. zero, 0); // read Proxy from Regedit. return issetproxyenabledok & issetproxyip & isnotifyok & isreadok & isconnectionok;} # endregion # region setconnection function Private Static bool setconnection (bool isproxyenabled, string proxyip) {string regpath = "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ connections "; // Connection register option. byte [] szbuf = new byte [80]; szbuf [0] = 0x3c; szbuf [4] = 0x09; szbuf [8] = (byte) (isproxyenabled? 0x03: 0x01); szbuf [12] = (byte) proxyip. length; For (INT I = 0; I <proxyip. length; I ++) {szbuf [I + 16] = (byte) convert. toint32 (proxyip [I]);} string local = "<local>"; for (Int J = 0; j <7; j ++) {szbuf [20 + proxyip. length + J] = (byte) convert. toint32 (local [J]);} return regeditsp. write (regeditsp. regedit_root_set.hkey_current_user, regpath, "Broadband connection", szbuf, true) ;}# endregion }}
Add the project code http://download.csdn.net/detail/xxdddail/5831359. The project implements the function of automatically swiping web pages with the proxy IP list.