How to add User agent for Network program, I recommend using Urlmksetsessionoption function,
However, the function has a weakness can not be X64 compiled, X86 compiled software can call the function
Otherwise it will always return! S_OK meaning error. Second, I suggest you look for something similar on the internet.
http://www.proxy.com.ru/Free proxy website, the code of the agent is found on the Internet
A few days later you are using my code there is no proxy effect because the proxy server is invalid, all subsequent
Need to consult the method of their own to find a free proxy server address Don't say I didn't remind you.
I do not recommend that you use the InternetSetOption function in the WinInet layer,
unless it is necessary Otherwise, I suggest you use my method above.
Example code:
private void Form1_Load (object sender, EventArgs e) { setuserproxy ("210.152.131.254:3128", NULL, NULL); WebBrowser1.Navigate ("Http://www.baidu.com/s?wd=ip"); }
The use of this method only need a few simple words can be done to deal with the gray often convenient.
[StructLayout (layoutkind.sequential, CharSet = charset.ansi)] public struct Internet_proxy_info { public int dwaccesstype; public string Lpszproxy; public string LpszProxyBypass; } [DllImport ("Urlmon.dll", SetLastError = true, CharSet = CharSet.Ansi)] public static extern int Urlmksetse ssionoption (int dwoption, ref internet_proxy_info pbuffer, int dwbufferlength, int dwreserved); [DllImport ("Urlmon.dll", SetLastError = true, CharSet = CharSet.Ansi)] public static extern int Urlmksetsessionopti On (int dwoption, string pbuffer, int dwbufferlength, int dwreserved); public const int S_OK = 0; public const int NULL = 0; public const int internet_open_type_proxy = 3; public const int internet_option_proxy = 38; public const int internet_option_proxy_username = 43; public const int Internet_option_proxy_password = 44; Network Proxy private bool SetuserproXY (string address, string Username, string password) {username = username?? string. Empty; Password = password?? String. Empty; var sproxy = new Internet_proxy_info () {lpszproxy = address, dwAccessType = INTE Rnet_open_type_proxy}; Urlmksetsessionoption (Internet_option_proxy_username, USERNAME, USERNAME. Length, NULL); Urlmksetsessionoption (Internet_option_proxy_password, PASSWORD, PASSWORD. Length, NULL); Return Urlmksetsessionoption (Internet_option_proxy, ref SPROXY, N, NULL) = = S_OK; }The above code is also relatively simple, first to open up a internet_proxy_info structure, accounting for 12 bytes
then open the proxy in the. dwAccessType Assignment Internet_open_type_proxy . Lpszproxy Assignment Agent
After the address of the server, set the proxy user name, proxy user password and pass the PIPI structure to the function test
The return value is not S_OK if it is returned true otherwise the false whole code is not very difficult.
C # Add a user agent to a network program