webbrowser代理c#代码实现
微软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#代码实现的更多相关文章
- Webbrowser代理支持
原文:Webbrowser代理支持 1 通过设置注册表,再用InternetSetOption发送INTERNET_OPTION_SETTINGS_CHANGED与INTERNET_OPTION_RE ...
- C# WebBrowser 代理的使用
原文:C# WebBrowser 代理的使用 The WebBrowser control is just an embeddded IE Control, I believe any setting ...
- JDK静态代理示例代码
JDK静态代理示例代码 业务接口 接口的实现类 代理类,实现接口,并扩展实现类的功能 1.业务接口 /** * 业务接口 * @author pc * */ public interface User ...
- java 27 - 10 反射之 动态代理的代码实现
为什么要写动态代理类? 例子: 如果现在想做个登陆注册的功能.用户可以执行登陆.注册.添加.删除这些功能. 但是,有些功能是要有一定权限才可以执行的. 而现在已经有了个用户类的接口和该类的实现类了,但 ...
- 通俗易懂详解Java代理及代码实战
一.概述 代理模式是Java常用的设计模式之一,实现代理模式要求代理类和委托类(被代理的类)具有相同的方法(提供相同的服务),代理类对象自身并不实现真正的核心逻辑,而是通过调用委托类对象的相关方法来处 ...
- Spring框架的AOP的底层实现之JDK的动态代理(代码了解,理解原理)
1.创建接口UserDao: package com.huida.demo1; public interface UserDao { public void save(); public void u ...
- JDK动态代理Demo代码,进一步学习分析
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflec ...
- Nginx代理前端代码
Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...
- 基于SOCK4网络协议的代理服务器端代码示例
//********************************************************************** #include <stdio.h> #i ...
随机推荐
- IOS开发问题录:如何在Swift中引入Head文件?
最近在学习IOS开发,从一个简单的登录开始,逐步解决了一个网络访问.获取控件值等问题,遇到了信息加密的问题. 做为IOS的入门者,信息加密需要解决如下几个问题: 1.IOS的MD5加密有没有固定函数, ...
- layoutSubviews -- setNeedsLayout -- layoutIfNeeded -- 区别
-layoutSubviews方法:这个方法,默认没有做任何事情,需要子类进行重写-setNeedsLayout方法: 标记为需要重新布局,异步调用layoutIfNeeded刷新布局,不立即刷新,但 ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料【转】
转自:机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一 ...
- python re 正则表达式[转]
01.#!/usr/bin/env python 02.# -*- coding: utf-8 -*- 03.import re 04. 05.def regex(): 06. str = 'abcd ...
- sqlserver 类似oracle的rownum功能: row_number
select row_number() over(order by t.id ) as num,id,name from (SELECT distinct [列 0] as id ,[列 1] as ...
- vim分屏快捷键使用/增大/减小字体使用
问题描述: vim分屏快捷键使用 问题解决: (1)vim 分屏快捷键 (2)vim高度改变 (3)vim中增加和减少字体大小 使用快捷键Ctr ...
- Castle 开发系统文章
转: http://www.cnblogs.com/Jebel/archive/2008/06/24/1228766.html
- spring @resource @ Autowired
Spring中什么时候用@Resource,什么时候用@service 当你需要定义某个类为一个bean,则在这个类的类名前一行使用@Service("XXX"),就相当于讲这个类 ...
- 管道命令xargs
在研究hadoop的过程中,遇到一个小难题. 问题描述:我需要将文件夹A下的文件拷贝到文件夹B中,但是以hadoop开头的文件不要拷贝. 问题解决:ls A|grep -v hadoop|xargs ...
- Synchronized Methods
Synchronized Methods The Java programming language provides two basic synchronization idioms: synchr ...