麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C# > 正文

webBrowser代理設置c#代碼

2020-01-24 03:38:24
字體:
來源:轉載
供稿:網友
為webBrowser設置代理:
復制代碼 代碼如下:

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)//strProxy為代理IP:端口
{
const int INTERNET_OPTION_PROXY = 38;
const int INTERNET_OPEN_TYPE_PROXY = 3;
const int INTERNET_OPEN_TYPE_DIRECT = 1;
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));
if (string.IsNullOrEmpty(strProxy) || strProxy.Trim().Length == 0)
{
strProxy = string.Empty;
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
}
// Converting structure to IntPtr
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}
使用:RefreshIESettings("xxx.xxx.xxx.xxx:xx");
完美方法:
/*完整解析
public class IEProxy
{
private const int INTERNET_OPTION_PROXY = 38;
private const int INTERNET_OPEN_TYPE_PROXY = 3;
private const int INTERNET_OPEN_TYPE_DIRECT = 1;
private string ProxyStr;
[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
}
private bool InternetSetOption(string strProxy)
{
int bufferLength;
IntPtr intptrStruct;
Struct_INTERNET_PROXY_INFO struct_IPI;
if (string.IsNullOrEmpty(strProxy) || strProxy.Trim().Length == 0)
{
strProxy = string.Empty;
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
}
else
{
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
}
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
bufferLength = Marshal.SizeOf(struct_IPI);
intptrStruct = Marshal.AllocCoTaskMem(bufferLength);
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
return InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, bufferLength);
}
public IEProxy(string strProxy)
{
this.ProxyStr = strProxy;
}
//設置代理
public bool RefreshIESettings()
{
return InternetSetOption(this.ProxyStr);
}
//取消代理
public bool DisableIEProxy()
{
return InternetSetOption(string.Empty);
}
}
*/
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美国产一区二区三区激情无套 | 精品一区二区久久久久久久网精 | 久久日韩在线 | 撅高 自己扒开 调教 | 久久精品之 | 99日韩精品视频 | 欧美高清在线精品一区二区不卡 | 法国性hdfreexxxx人妖 | av在线更新 | 久久精品国产99国产精品亚洲 | 鲁人人人鲁人人鲁精品 | 18视频在线观看娇喘 | 成人国产在线看 | 免费在线国产 | 99国产精品欲a | 天天躁狠狠躁夜躁2020挡不住 | 成人免费自拍视频 | 日韩在线激情 | 国产色视频在线观看免费 | 色婷婷久久一区二区 | 手机国产乱子伦精品视频 | 亚洲电影在线播放 | 日本大片在线播放 | 在线看小早川怜子av | 成人在线视频免费播放 | 久久精品性视频 | 九色一区二区 | 9999精品| 国产一区二区在线免费播放 | 国av在线| 91精品国产综合久久男男 | 久久91精品久久久久清纯 | 毛片在哪里看 | 精品国产一区二区三区四区在线 | 免费黄色在线电影 | 黄色毛片免费视频 | 久久综合入口 | 成人男女啪啪免费观看网站四虎 | 中文字幕欧美一区二区三区 | 亚久久| 久久久精品视频免费 |