By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,786 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,786 IT Pros & Developers. It's quick & easy.

set proxy for web browser control in

P: 3
I have used web browser control. I want to use different web proxy on each web request. how to set proxy for web browser control??

reply me as soon as possible.
Aug 30 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 4,871
The WebBrowser control is just an embeddded IE Control, I believe any settings in IE, like the proxy settings, are honered just the same as they are in IE.

You can change the proxy with InternetSetOption method from the wininet.dll, here is a C# example to set the proxy:
Expand|Select|Wrap|Line Numbers
  1. Public struct Struct_INTERNET_PROXY_INFO 
  2. public int dwAccessType; 
  3. public IntPtr proxy; 
  4. public IntPtr proxyBypass; 
  5. }; 
  7. [DllImport("wininet.dll", SetLastError = true)] 
  8. private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
  10. private void RefreshIESettings(string strProxy) 
  11. const int INTERNET_OPTION_PROXY = 38; 
  12. const int INTERNET_OPEN_TYPE_PROXY = 3; 
  14. Struct_INTERNET_PROXY_INFO struct_IPI; 
  16. // Filling in structure 
  17. struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY; 
  18. struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy); 
  19. struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local"); 
  21. // Allocating memory 
  22. IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI)); 
  24. // Converting structure to IntPtr 
  25. Marshal.StructureToPtr(struct_IPI, intptrStruct, true); 
  27. bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI)); 
  29. private void SomeFunc() 
  30. RefreshIESettings(""); 
  32. System.Object nullObject = 0; 
  33. string strTemp = String.Empty; 
  34. System.Object nullObjStr = strTemp;
  35. axWebBrowser1.Navigate("", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr); 
  36. }
Sep 1 '08 #2

P: 3
Thank you kenobewan.

I have used this solution, but I think It is not working. if I open I get my original ip instead of any other( ip of web proxy which I have used.)

you told me that "The WebBrowser control is just an embeddded IE Control". yes I agree. but is there any other way to set proxy for WB control.

reason behind proxy settings is I want to use different ip on each request to web server.

is there any other way to do it?? can u suggest me any other control for this purpose??

any help or suggestion is appreciated.
Sep 2 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.