让webbrowser也可以设置代理服务器
来源:互联网 发布:java内存泄露他检测 编辑:程序博客网 时间:2024/04/28 23:46
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
namespace _g
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)WebRequest.Create("http://book.3g.cn/index.aspx?cin=3&sid=&frcin=1&rd=38");
//WebProxy _WP = new WebProxy("211.95.176.6", 808);
//_WP.BypassProxyOnLocal = true;
//ICredentials credentials = new NetworkCredential("","","");
//_WP.Credentials = credentials;
//req.Accept = "TCL E737 TCL-e737/401/WAP-2.0/MIDP-1.0/CLDC-1.0";
//req.Proxy = _WP;
//System.IO.Stream str=null;
//System.IO.StreamReader sr=null;
//System.Net.WebResponse webresponse=null;
//try
//{
// webresponse = req.GetResponse();
// str = webresponse.GetResponseStream();
// string PageCode = "gb2312";
RefreshIESettings("211.95.176.6:808");
System.Object nullObject = 0;
string strTemp = String.Empty;
System.Object nullObjStr = strTemp;
this.webBrowser1.Navigate("http://book.3g.cn/index.aspx?cin=3&sid=&frcin=1&rd=38", null, null, null);
//if ((webresponse.ContentType != null) && (webresponse.ContentType.IndexOf("charset") != -1)) //处理页面编码,页面有设置则按设置,否则按系统默认编码
//{
//MessageBox.Show(response.ContentType.ToString());
//PageCode = GetCharType(webresponse.ContentType.ToString());
//sr = new StreamReader(str, System.Text.Encoding.GetEncoding(PageCode));
// this.richTextBox1.Text = sr.ReadToEnd();
//}
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
//finally
//{
// str.Close();
// sr.Close();
//}
}
private string GetCharType(string tmp1) //获取页面编码
{
string tmp = "";
tmp = tmp1;
int a = tmp.IndexOf("charset=") + 8;
tmp = tmp.Substring(a, tmp.Length - a);
return tmp;
}
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
RefreshIESettings("211.95.176.6:808");
using System.Runtime.InteropServices;//需要添加这个引用
- 让webbrowser也可以设置代理服务器
- 对WebBrowser控件设置独立的代理服务器
- Delphi 设置WebBrowser 代理服务器 与 UserAgent
- 让iframe的高度height也可以设置百分比数值
- 用Winform的WebBrowser开发可设置代理服务器的浏览器
- 让Fetch()也可以Timeout
- 采用以下方法可以让console显示英文,同时保持xwindow为中文(也可以设置xwindow用英文)
- 让ASP也可以连接MYSQL
- 让ASP也可以连接MYSQL
- 如何让手机也可以记录log
- 让VS2005也可以编译驱动
- 让VS2005也可以编译驱动
- 让C#事件也可以异步触发
- 让ASP也可以连接MYSQL
- 让C#事件也可以异步触发
- 让linux也可以使用pbcopy
- 让无代理设置参数的软件通过代理服务器联网
- ubuntu也可以设置成中文语言
- 人生12个经典领悟
- Struts 2框架配置
- PowerDesign的一些问题
- 第一篇
- 用c写的线性表的顺序实现
- 让webbrowser也可以设置代理服务器
- delphi下实现控制其它窗体中的控件
- 如何将秒转换成时分秒格式
- c# .net 如何截取当前程序窗口指定位置的截图
- 什么情况下可能出现临时对象?
- 小小的一个密封件截面尺寸最大不过几厘米
- [数据恢复答疑]IBM 的RAID5E和RAID5EE适合我吗?
- Head First C# 中文版 图文皆译 第六章 继承 page215
- 十个故事(从故事中看出创业必备的精神)