微软webbrowser控件也就是IE插件,他的所有功能就像IE类似,当然设置也是一样的,下面介绍下webbrowser如何设置代理,可不要用这个对抗广告联盟哦

You can change the proxy with InternetSetOption method from the wininet.dll, here is a example to set the proxy:

using System.Runtime.InteropServices;

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

-------------------------------------------------------------------------------------------------------------------------------------

昨 天做的投票机遇到个新问题,昨天开始那个投票开始现在ip地址,每个地址只能投5票/天。如果每次更改ie的连接为代理服务器,那也麻烦死了,如 果改用webclient,那昨天的2个多小时就白费了,上网一通狂收还真找到了办法,这下好办了,建了一个proxy.txt文档,里面放上从网上收到 的代理服务器,然后程序读到一个listbox里面,每次需要更换ip的时候只要单击一次,就可以还一个地址重新投票了。 
附上proxy.cs 

using System.Runtime.InteropServices;//需要添加这个引用 
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); 
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)); 
}

使用的时候,调用RefreshIESettings 
py.proxy py1 = new proxy(); 
py1.RefreshIESettings(”221.4.155.51:3128″);

webBrowser1.Navigate(”http://www.hfxsy.cn”, null, null, null);

webbrowser代理c#代码实现的更多相关文章

  1. Webbrowser代理支持

    原文:Webbrowser代理支持 1 通过设置注册表,再用InternetSetOption发送INTERNET_OPTION_SETTINGS_CHANGED与INTERNET_OPTION_RE ...

  2. C# WebBrowser 代理的使用

    原文:C# WebBrowser 代理的使用 The WebBrowser control is just an embeddded IE Control, I believe any setting ...

  3. JDK静态代理示例代码

    JDK静态代理示例代码 业务接口 接口的实现类 代理类,实现接口,并扩展实现类的功能 1.业务接口 /** * 业务接口 * @author pc * */ public interface User ...

  4. java 27 - 10 反射之 动态代理的代码实现

    为什么要写动态代理类? 例子: 如果现在想做个登陆注册的功能.用户可以执行登陆.注册.添加.删除这些功能. 但是,有些功能是要有一定权限才可以执行的. 而现在已经有了个用户类的接口和该类的实现类了,但 ...

  5. 通俗易懂详解Java代理及代码实战

    一.概述 代理模式是Java常用的设计模式之一,实现代理模式要求代理类和委托类(被代理的类)具有相同的方法(提供相同的服务),代理类对象自身并不实现真正的核心逻辑,而是通过调用委托类对象的相关方法来处 ...

  6. Spring框架的AOP的底层实现之JDK的动态代理(代码了解,理解原理)

    1.创建接口UserDao: package com.huida.demo1; public interface UserDao { public void save(); public void u ...

  7. JDK动态代理Demo代码,进一步学习分析

    import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflec ...

  8. Nginx代理前端代码

    Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...

  9. 基于SOCK4网络协议的代理服务器端代码示例

    //********************************************************************** #include <stdio.h> #i ...

随机推荐

  1. C++中的运算符优先级

    1   ()  []  .  ->2   !  ~   -(负号) ++  --   &(取变量地址)*   (type)(强制类型)    sizeof 3   * / % 4   + ...

  2. 数字式PID控制的应用总结

    PID控制是一个二阶线性闭环控制器,通过调整比例.积分和微分三项参数,使得大多数的工业控制系统获得良好的闭环控制性能.PID控制优点:a. 技术成熟,b. 易被人们熟悉和掌握,c. 不需要建立数学模型 ...

  3. Oracle 临时事务表 全局临时表_global temporary table

    所有的操作都在一个事务里,事务提交后,此表清空,特别适合做插入删除频率特别高的临时表操作,比如插入完数据就开始查询,查询完就删掉等,用完就扔! 临时表分事务级临时表和会话级临时表. 事务级临时表只对当 ...

  4. Error: Exception in thread “main” java.lang.NoClassDefFoundError错误

    Error: Exception in thread “main” java.lang.NoClassDefFoundError错误 检查文件名与类名是否一致 检查程序中main方法写的是否正确: p ...

  5. Memcache安全配置

    Memcache安全配置 瞌睡龙 · 2014/01/20 17:59 0x00 Memcache简介 Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash ...

  6. 解决ORA-00020错误

    解决ORA-00020错误 分类: Oracle2009-05-13 17:26 3398人阅读 评论(0) 收藏 举报 数据库sessionoraclesql服务器object 项目上使用的Orac ...

  7. solr4.5部署

    一.服务器部署 1.solr自带jetty服务器上部署 cd到solr-4.5.0\example目录下,运行java -jar start.jar即可运行jetty服务器.访问http://loca ...

  8. ios 沙盒 NSCoding(相当于JAVA对象序列化) 归档 数据存储

    通过NSCoding能实现像JAVA一样能够实现对象的序列化,可以保存对象到文件里. NSCoding 跟其他存储方式略有不同,他可以存储对象 对象存储的条件是: 对象需要遵守 NSCoding 协议 ...

  9. hdu2011

    http://acm.hdu.edu.cn/showproblem.php?pid=2011 #include<iostream> #include<math.h> #incl ...

  10. 李洪强漫谈iOS开发[C语言-009] - C语言关键字

    // //  main.m //  04 - C语言关键字 // //  Created by vic fan on 16/7/12. //  Copyright © 2016年 李洪强. All r ...