WebBrowser如何设置代理服务器

tgtt 2009-03-08 04:29:23
        public 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));
}


貌视并不起作用

在我访问http://www.ip.cn/的时候,那上面显示我的IP地址始终不变

“您当前的IP是:121.35.189.188 来自:广东省深圳市 电信”

看来代理服务器并没有起作用

请问大家有什么好的方法吗?
...全文
207 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shiboss 2009-03-09
  • 打赏
  • 举报
回复
学习 帮顶
tgtt 2009-03-09
  • 打赏
  • 举报
回复
楼上的也不可行的,显示的IP还是没变

是不是用代理服务器并不能改变自己访问端的IP地址?
cppfaq 2009-03-08
  • 打赏
  • 举报
回复
试下这个,good luck:

 [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()
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
//更改健值,设置代理,
optionKey.SetValue("ProxyEnable", 1);
optionKey.SetValue("ProxyServer", "192.168.1.85:80");

//激活代理设置
InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧