-1

I found a way to set up proxy in webbrowser on stackoverflow.

How to set a proxy for Webbrowser Control without effecting the SYSTEM/IE proxy

public struct Struct_INTERNET_PROXY_INFO
{
    public int dwAccessType;
    public IntPtr proxy;
    public IntPtr proxyBypass;
};

[DllImport("wininet.dll", SetLastError = true)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

//to activate use like this strProxy="85.45.66.25:3633"
//to deactivate use like this strProxy=":"
public static void RefreshIESettings(string strProxy)
{
    try
    {
        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));
    }
    catch (Exception ex)
    {

        //TB.ErrorLog(ex);
    }
}

private void SomeFunc()
{
     RefreshIESettings("1.2.3.4:8080");
     //or RefreshIESettings("http://1.2.3.4:8080"); //both worked
     //or RefreshIESettings("http=1.2.3.4:8080"); //both worked

     System.Object nullObject = 0;
     string strTemp = "";
     System.Object nullObjStr = strTemp;
     WebBrowser1.Navigate("http://willstay.tripod.com");
}

However, this code is a proxy setting for all web browsers. I have multiple web browsers in the form, and I want to proxy only one web browser among them.

Using proxy with WebBrowser and WebRequest, how to include username and password? And I found this, but it didn't help me.

Can I solve this problem if I create a custom usercontrol that can connect to a proxy and then inherit the webbrowser?

Any helpful information would be appreciated

Sh H
  • 53
  • 4

1 Answers1

0

I was able to set each proxy after changing to the chromium window.

Sh H
  • 53
  • 4