469,117 Members | 1,313 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,117 developers. It's quick & easy.

set proxy for web browser control in vb.net

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
2 7669
kenobewan
4,871 Expert 4TB
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. }; 
  6.  
  7. [DllImport("wininet.dll", SetLastError = true)] 
  8. private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
  9.  
  10. private void RefreshIESettings(string strProxy) 
  11. const int INTERNET_OPTION_PROXY = 38; 
  12. const int INTERNET_OPEN_TYPE_PROXY = 3; 
  13.  
  14. Struct_INTERNET_PROXY_INFO struct_IPI; 
  15.  
  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"); 
  20.  
  21. // Allocating memory 
  22. IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI)); 
  23.  
  24. // Converting structure to IntPtr 
  25. Marshal.StructureToPtr(struct_IPI, intptrStruct, true); 
  26.  
  27. bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI)); 
  28.  
  29. private void SomeFunc() 
  30. RefreshIESettings("192.168.1.200:1010"); 
  31.  
  32. System.Object nullObject = 0; 
  33. string strTemp = String.Empty; 
  34. System.Object nullObjStr = strTemp;
  35. axWebBrowser1.Navigate("http://willstay.tripod.com", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr); 
  36. }
Sep 1 '08 #2
Thank you kenobewan.

I have used this solution, but I think It is not working. if I open whatismyip.com 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.

Similar topics

16 posts views Thread by Paul Sweeney | last post: by
3 posts views Thread by Soul | last post: by
7 posts views Thread by Pro1712 | last post: by
reply views Thread by Dan Lenski | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.