In fact, the use of WebBrowser in C # Everyone should be, the forum also has a lot of examples before you can find out
But the way to set up proxies just like a browser can be a lot of people don't know yet.
This is actually called a DLL file to set,
Now let's see it with me.
First of all, we must first build a structure that is the proxy information structure
As follows
[C #]Plain Text view copy code ?
| 010203040506070809 |
/// <summary> /// 代理结构体 /// </summary> public struct Struct_INTERNET_PROXY_INFO { public int dwAccessType; public IntPtr proxy;//IP以及端口号 public IntPtr proxyBypass; }; |
Here's how to set up a specific implementation of the agent
[C #]Plain Text view copy code ?
| 01020304050607080910111213141516171819202122232425262728293031 |
/// <summary> /// 设置代理的Api /// </summary> /// <returns></returns> [DllImport("wininet.dll", SetLastError = true)] private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength); /// <summary> /// 代理IP以及端口号 /// </summary> /// <param name="strProxy"></param> private 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)); } |
It's very easy to use.
[C #]Plain Text view copy code ?
| 0102 |
RefreshIESettings("41.129.53.227:80");webBrowser1.Navigate("http://www.sufeinet.com"); |
That's all you can do.
All right, everybody, try it yourself.
C#webbrowser How to use a proxy server WinForm