关闭代理c#

问题描述 投票:1回答:3

这是打开代理的代码:

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

但是我如何关闭????谢谢

c# proxy setting
3个回答

0
投票

好像是在不久前问过这个问题的,但是我花了最后两个小时研究了这个问题,却找不到答案。最终,我偶然发现了一个晦涩难懂的网站,上面有有效的代码。

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

像这样呼叫RefreshIESettingsRefreshIESettings(":")


0
投票

更改此代码块的刷新设置。像这样调用此代码。 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));

}
© www.soinside.com 2019 - 2024. All rights reserved.