关闭代理c#

发布于 2024-09-18 11:58:25 字数 1416 浏览 6 评论 0原文

这是打开代理的代码:

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

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

private void RefreshIESettings(string strProxy) 
{ 
    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)); 
} 

private void SomeFunc() 
{ 
    RefreshIESettings("192.168.1.200:1010"); 

    System.Object nullObject = 0; 
    string strTemp = String.Empty; 
    System.Object nullObjStr = strTemp;
    axWebBrowser1.Navigate("http://willstay.tripod.com", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr); 
}

但是我怎样才能关闭呢??? 谢谢

this is the code to turn on the proxy:

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

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

private void RefreshIESettings(string strProxy) 
{ 
    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)); 
} 

private void SomeFunc() 
{ 
    RefreshIESettings("192.168.1.200:1010"); 

    System.Object nullObject = 0; 
    string strTemp = String.Empty; 
    System.Object nullObjStr = strTemp;
    axWebBrowser1.Navigate("http://willstay.tripod.com", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr); 
}

but how can i turn off??????
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泪眸﹌ 2024-09-25 11:58:25

看起来这个问题很久以前就被问过,但我花了最后两个小时研究这个问题,但找不到答案。最后我偶然发现了一些不起眼的网站,其中的代码可以工作。

再次尝试上面的代码,但不要指定实际的代理地址,而是使用 ":"

像这样调用 RefreshIESettingsRefreshIESettings(":")

Looks like this question was asked some time ago, but I just spent the last 2 hours researching this and couldn't find an answer. Finally I found some obscure site on accident with code that works.

Try your code above again, but instead of specifying the actual proxy address, use ":" instead.

Call RefreshIESettings like so: RefreshIESettings(":")

对你而言 2024-09-25 11:58:25

像此代码块一样更改 RefreshIEsettings。
只需像这样调用这段代码即可。刷新IE设置(“:”)

public static void RefreshIESettings(string strProxy)
{
    const int INTERNET_OPTION_PROXY = 38;
    const int INTERNET_OPEN_TYPE_PROXY = 3;
    const int INTERNET_OPEN_TYPE_DIRECT = 1;

    Struct_INTERNET_PROXY_INFO struct_IPI;

    // Filling in structure 
    if (strProxy==":")
    {
        struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
    }
    else
    {
        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));

}

Change RefreshIESettings like this code block.
Just call this code like this. RefreshIESettings(":")

public static void RefreshIESettings(string strProxy)
{
    const int INTERNET_OPTION_PROXY = 38;
    const int INTERNET_OPEN_TYPE_PROXY = 3;
    const int INTERNET_OPEN_TYPE_DIRECT = 1;

    Struct_INTERNET_PROXY_INFO struct_IPI;

    // Filling in structure 
    if (strProxy==":")
    {
        struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
    }
    else
    {
        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));

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文