我已经使用此代码一段时间成功地将代理分配给IE然后我使用WebBrowser
控件导航到页面(不能以任何其他方式HttpWebRequest
等原因导致某些原因)。
代码是:
private void ChangeProxySetting(String proxyHost, Boolean proxyEnabled)
{
const int INTERNET_OPTION_PROXY = 38;
const int INTERNET_OPEN_TYPE_PROXY = 3;
Struct_INTERNET_PROXY_INFO struct_IPI;
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(proxyHost);
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}
但是突然代码停止了工作;它绕过了没有错误仍然返回TRUE但我在IE中看不到任何代理。
在它通过这一行之前,IE有一个代理服务器!
有什么建议吗?还是比注册表方式?