【问题标题】:Can I set proxy only for the webbrowser I want?我可以只为我想要的网络浏览器设置代理吗?
【发布时间】:2020-12-01 19:30:30
【问题描述】:

我找到了一种在 stackoverflow 上的 webbrowser 中设置代理的方法。

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");
}

但是,此代码是所有网络浏览器的代理设置。我在表单中有多个网络浏览器,我只想代理其中一个网络浏览器。

Using proxy with WebBrowser and WebRequest, how to include username and password? 我找到了这个,但对我没有帮助。

如果我创建一个可以连接到代理然后继承网络浏览器的自定义用户控件,我可以解决这个问题吗?

任何有用的信息将不胜感激

【问题讨论】:

    标签: winforms


    【解决方案1】:

    切换到铬窗口后,我能够设置每个代理。

    【讨论】:

      猜你喜欢
      • 2010-10-27
      • 2020-08-23
      • 1970-01-01
      • 2021-01-05
      • 1970-01-01
      • 2014-09-27
      • 2011-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多