C# WebBrowser 代理的使用

简介: 原文:C# WebBrowser 代理的使用  The WebBrowser control is just an embeddded IE Control, I believe any settings in IE, like the proxy settings, are honered just the same as they are in IE.
原文: C# WebBrowser 代理的使用

 

The WebBrowser control is just an embeddded IE Control, I believe any settings in IE, like the proxy settings, are honered just the same as they are in IE.

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

 

img_1c53668bcee393edac0d7b3b3daff1ae.gifimg_405b18b4b6584ae338e0f6ecaf736533.gifCode

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

目录
相关文章
|
C#
C#webBrowser使用代理服务器的方法winform
其实在C#中使用webBrowser大家应该都会了,论坛也有很多相前的例子大家可以查询一下就知道了但是像直接使用浏览器一样设置代理 的方法可能很多人还不知道吧。这个其实是调用一个Dll文件进行设置的,下面大家跟我一起来看看吧首先还是要先建一个结构就是代理信息的结构体如下 [C#] 纯文本查看 复制...
1431 0
|
C#
C# winform webbrowser如何指定内核为IE11? 输出 this.webbrowser.Version 显示版本是IE11的,但实际版本不是啊! 网上打的修改注册表HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet
最佳答案   1)假设你应用程序的名字为MyApplication.exe 2)运行Regedit,打开注册表,找到 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\...
2374 0
|
C#
C# 修改webbrowser 的 useragent
Also, there is a refresh option in the function (according to MSDN). It worked well for me (you should set it before any user agent change).
2674 0
|
Linux C# Android开发
C#爬虫使用代理刷csdn文章浏览量
昨天写了一篇关于“c#批量抓取免费代理并验证有效性”的文章,接着昨天的目标继续完成吧,最终实现的目的就是刷新csdn文章的浏览量(实际上很简单,之前博客园的文章也是可以使用代理ip来刷的,后来不行了),刷文章的浏览量本身是可耻的,没有任何意义,当然技术无罪。
1596 0
|
NoSQL C# Redis
c#批量抓取免费代理并验证有效性
之前看到某公司的官网的文章的浏览量刷新一次网页就会增加一次,给人的感觉不太好,一个公司的官网给人如此直白的漏洞,我批量发起请求的时候发现页面打开都报错,100多人的公司的官网文章刷新一次你给我看这个,这公司以前来过我们学校宣传招人+在园子里搜招聘的时候发现居然以前招xamarin,挺好奇的,所以就关注过。
1413 0
|
JavaScript C# 前端开发
c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
原文:c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 可以实现例如通过应用程序操作google搜索,用户输入要搜索的内容,然后在google中搜索;可以自动点击网页上的按钮等功能     1.
2471 0