[DllImport(@"wininet",
SetLastError = true,
CharSet = CharSet.Auto,
EntryPoint = "InternetSetOption",
CallingConvention = CallingConvention.StdCall)]
public static extern bool InternetSetOption
(
int hInternet,
int dmOption,
IntPtr lpBuffer,
int dwBufferLength
); public static void SetProxy(string ip, bool isProxy)
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
//更改健值,设置代理,
if (isProxy)
{
optionKey.SetValue("ProxyEnable", 1);
optionKey.SetValue("ProxyServer", ip);
}
else
{
optionKey.SetValue("ProxyEnable", 0);
optionKey.DeleteValue("ProxyServer");
}
//激活代理设置
InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
}界面上有个WebBrowser控件,我通过主线程调用SetProxy方法后,再通过WebBrowser.Navigate("http://ipseeker.cn/");后能成功实现代理访问,ipseeker.cn能显示代理的IP地址但是我通过新建线程同样先后调用SetProxy和WebBrowser.Navigate("http://ipseeker.cn/"); ipseeker.cn能显示的是本机的真是IP请问这个问题怎么处理???
SetLastError = true,
CharSet = CharSet.Auto,
EntryPoint = "InternetSetOption",
CallingConvention = CallingConvention.StdCall)]
public static extern bool InternetSetOption
(
int hInternet,
int dmOption,
IntPtr lpBuffer,
int dwBufferLength
); public static void SetProxy(string ip, bool isProxy)
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
//更改健值,设置代理,
if (isProxy)
{
optionKey.SetValue("ProxyEnable", 1);
optionKey.SetValue("ProxyServer", ip);
}
else
{
optionKey.SetValue("ProxyEnable", 0);
optionKey.DeleteValue("ProxyServer");
}
//激活代理设置
InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
}界面上有个WebBrowser控件,我通过主线程调用SetProxy方法后,再通过WebBrowser.Navigate("http://ipseeker.cn/");后能成功实现代理访问,ipseeker.cn能显示代理的IP地址但是我通过新建线程同样先后调用SetProxy和WebBrowser.Navigate("http://ipseeker.cn/"); ipseeker.cn能显示的是本机的真是IP请问这个问题怎么处理???
1 通过设置注册表,再用InternetSetOption发送INTERNET_OPTION_SETTINGS_CHANGED与INTERNET_OPTION_REFRESH信息,可以将注册表中的数据重新取出,从而对当前进程中的webbrowser进行设置.2 自定义一个INTERNET_PER_CONN_OPTION_LIST对象,然后定义一组INTERNET_PER_CONN_OPTION对象,将这一组对象的赋值给INTERNET_PER_CONN_OPTION_LIST,再InternetSetOption对INTERNET_PER_CONN_OPTION_LIST指令进行刷新.3 采用PAC文件,先编写好PAC,可以配合自定义HELPER FUNCTIONS,在AutoProxyHelperVtbl中指出调用的函数,然后再采用InternetInitializeAutoProxyDll指定PAC文件位置及AutoProxyHelperVtbl对象.