C#设置当前程序通过IE代理服务器上网
来源:互联网 发布:html 图片存进数据库 编辑:程序博客网 时间:2024/06/05 08:59
注意:以下设置只在当前程序中有效,对IE浏览器无效,且关闭程序后,自动释放代码。
Proxy.cs类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
public static class Proxy
{
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 static void SetIEProxy(string strProxy)
{
const int INTERNET_OPTION_PROXY = 38;
const int INTERNET_OPEN_TYPE_PROXY = 3;
Struct_INTERNET_PROXY_INFO struct_IPI;
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}
}
设置代理:Proxy.SetIEProxy("127.0.0.1:8080");
取消代理:Proxy.SetIEProxy(string.Empty); //设置为空即可
Proxy类下载:点击下载
- C#设置当前程序通过IE代理服务器上网
- c#设置取消ie代理服务器
- IE 代理服务器设置程序实现
- IE 代理服务器设置程序实现
- IE 代理服务器设置程序实现
- IE 代理服务器设置程序实现
- IE 代理服务器设置程序实现
- 基于c#的IE 代理服务器设置
- Java通过代理服务器上网
- 远程操作linux网络设置(一)-通过代理服务器上网
- 宽带上网-----代理服务器设置
- IE代理服务器设置
- mtk上网代理服务器设置问题
- Ubuntu 12.10代理服务器上网设置
- C# 程序设置IE主页
- 更改 IE 代理服务器的设置
- 如何设置IE禁用代理服务器
- [乐意黎]通过批处理来命令设置IE代理服务器的例子
- js中apply方法的使用
- java压缩文件方法
- 新建用户并添加到管理组
- cocos2dx输出Log的几种方法
- android 手电筒 代码
- C#设置当前程序通过IE代理服务器上网
- PHP中通过socket实现聊天功能
- 经典问题总结(三)
- 01背包 HDU2602
- android中的Handler
- PHP简单练习代码
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- linux 初学者常用目录结构学习
- poj1125 (Floyd)