1. 程式人生 > >C# webBrowser 通過代理訪問網頁

C# webBrowser 通過代理訪問網頁

改變webBrowser1的代理

程式碼

#region 改變代理
        [DllImport("wininet.dll", SetLastError = true)]
        private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

        public void RefreshIESettings(string strProxy)
        {
            const int INTERNET_OPTION_PROXY = 38;
            const int INTERNET_OPEN_TYPE_PROXY = 3;
            Struct_INTERNET_PROXY_INFO struct_IPI;
            // Filling in structure 
            struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
            struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
            struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
            // Allocating memory 
            IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
            // Converting structure to IntPtr 
            Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
            bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
        }
        #endregion

讀取代理列表

c盤放了個代理的檔案列表


更改代理,訪問網站

免費代理的列表

211.144.219.66:80
222.74.34.190:808
121.8.171.40:3128
116.228.108.58:808
202.43.180.146:3128
58.215.78.157:808
61.134.27.214:8080
221.12.147.80:808
60.216.101.31:8080
123.139.158.189:3128

 大家誰完善了發個給我用用哈