微软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. Encog

    http://www.heatonresearch.com/encog/ https://www.mql5.com/zh/articles/252

  2. Hello BaiduMap

    百度提供了地图的API,可以在android手机上用,这里其实只要参考百度给的文档就好了.因为api不断在更新,所以网上的博客感觉还是不太好,直接看官网的文档比较靠谱 这里照着百度文档上面提供的文档我 ...

  3. Codeforces Round #343 (Div. 2) E. Famil Door and Roads

    题目链接: http://www.codeforces.com/contest/629/problem/E 题解: 树形dp. siz[x]为x这颗子树的节点个数(包括x自己) dep[x]表示x这个 ...

  4. 【Memcache】下载和安装

    下载: Win7 64bit 系统 下载过过很多版本,都无法安装,最后到这里下载,成功安装: http://blog.couchbase.com/memcached-windows-64-bit-pr ...

  5. 11个实用jQuery日历插件

    1. FullCalendar FullCalendar是很出名的jQuery日历插件,它支持拖拽等功能,整合了Google Calendar,而且可以通过JSON来绑定事件,设计师可以轻松地自定义日 ...

  6. Android串口通信(基于Tiny6410平台)

    友善之臂的Android系统有他们自己编写的一个串口通信程序,网上没有找到他的源代码,而且界面操作不在一个界面,不是很方便,这里我自己写了一个粗糙点的串口通信程序. 同样这里还是调用友善之臂的frie ...

  7. 【leetcode】Majority Element (easy)(*^__^*)

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  8. cojs 疯狂的求和问题 解题报告

    QAQ 好久不在cojs上出题了 最近学了点新科技,于是就做成题来分享了 这道题是要求simga(i^k) 那么就先说说部分分的算法吧: 10分: 直接暴力就可以了,时间复杂度O(nlogk) 30分 ...

  9. Libsvm学习

        本篇博客转自 http://www.cppblog.com/guijie/archive/2013/09/05/169034.html     在电脑文件夹E:\other\matlab 20 ...

  10. [z]Google SPDY介绍

    转自 http://blog.csdn.net/marcky/article/details/7728662 本文主要是参考Google SPDY项目主页的一些文档总结而来,目的整体上介绍SPDY协议 ...