C# webbrowser 代理

百度,google加自己理解后,將所得方法總結一下:

????方法1:修改注冊表Software//Microsoft//Windows//CurrentVersion//Internet SettingsProxyEnable和ProxyServer。這種方法適用于局域網用戶,撥號用戶無效。

????

?1?public?partial?class?Form1?:?Form
?2????{???????
?3
?4????????//用于刷新注冊表
?5????????[DllImport(@"wininet",
?6????????SetLastError?=?true,
?7????????CharSet?=?CharSet.Auto,
?8????????EntryPoint?=?"InternetSetOption",
?9????????CallingConvention?=?CallingConvention.StdCall)]
10
11
12????????public?static?extern?bool?InternetSetOption
13????????(
14????????int?hInternet,
15????????int?dmOption,
16????????IntPtr?lpBuffer,
17????????int?dwBufferLength
18????????);
19
20?????????private?void?btnStart_Click(object?sender,?EventArgs?e)
21????????{
22????????????RegistryKey?pregkey;
23????????????????pregkey?=?Registry.CurrentUser.OpenSubKey("Software//Microsoft//Windows//CurrentVersion//Internet?Settings",?true);
24????????????????if?(pregkey?==?null)
25????????????????{
26????????????????????Console.WriteLine("鍵值不存在");
27????????????????}

28????????????????else
29????????????????{
30????????????????????pregkey.SetValue("ProxyEnable",?1);
31????????????????????pregkey.SetValue("ProxyServer",?"代理地址");
32????????????????????//激活代理設置
33????????????????????InternetSetOption(0,?39,?IntPtr.Zero,?0);
34????????????????????InternetSetOption(0,?37,?IntPtr.Zero,?0);
35????????????????????webBrowser1.Navigate(txtweb.Text,?false);
36????????????????????//?System.Threading.Thread.Sleep(10000);
37????????????????}

38????????}

39}

方法2: 修改注冊表 Software//Microsoft//Windows//CurrentVersion//Internet Settings//Connections下以你撥號連接名為鍵的值,該鍵為二進制。這種方法適用于撥號用戶。

????
public?partial?class?FrmMain?:?Form
????
{

[DllImport(
@"wininet",
????????SetLastError?
=?true,
????????CharSet?
=?CharSet.Auto,
????????EntryPoint?
=?"InternetSetOption",
????????CallingConvention?
=?CallingConvention.StdCall)]


????????
public?static?extern?bool?InternetSetOption
????????(
????????
int?hInternet,
????????
int?dmOption,
????????IntPtr?lpBuffer,
????????
int?dwBufferLength
????????);

//將值轉換為注冊表中的二進制值
public?byte?ChangeTobyte(char?i)
????????
{
????????????
byte?key?=?0;
????????????
switch?(i)
????????????
{
????????????????
case?'0':?key?=?48;?break;
????????????????
case?'1':?key?=?49;?break;
????????????????
case?'2':?key?=?50;?break;
????????????????
case?'3':?key?=?51;?break;
????????????????
case?'4':?key?=?52;?break;
????????????????
case?'5':?key?=?53;?break;
????????????????
case?'6':?key?=?54;?break;
????????????????
case?'7':?key?=?55;?break;
????????????????
case?'8':?key?=?56;?break;
????????????????
case?'9':?key?=?57;?break;
????????????????
case?'.':?key?=?46;?break;
????????????????
case?':':?key?=?58;?break;
????????????????
????????????}

????????????
return?key;
????????}


private?void?btnStart_Click(object?sender,?EventArgs?e)
????????
{
?????????????
int?i?=?("代理地址").Length;
????????????????
byte[]?key?=?new?byte[50];
????????????????
char[]?source?=?("代理地址").ToCharArray();
????????????????key[
0]?=?60;
????????????????key[
4]?=?3;
????????????????key[
8]?=?3;
????????????????key[
12]?=?(byte)i;
????????????????
for?(int?ii?=?0;?ii?<?source.Length;?ii++)
????????????????
{
????????????????????key[
16?+?ii]?=?ChangeTobyte(source[ii]);
????????????????}

????????????????
string?sDirectX?=?"";
????????????????
for?(int?k?=?0;?k?<?key.Length;?k++)
????????????????
{
????????????????????
if?(key[k]?!=?0)
????????????????????
{
????????????????????????sDirectX?
+=?key[k]?+?"?";
????????????????????}

????????????????}

????????????????
//MessageBox.Show(sDirectX);
????????????????RegistryKey?pregkey;
????????????????pregkey?
=?Registry.CurrentUser.OpenSubKey("Software//Microsoft//Windows//CurrentVersion//Internet?Settings//Connections",?true);
????????????????
if?(pregkey?==?null)
????????????????
{
????????????????????Console.WriteLine(
"鍵值不存在");
????????????????}

????????????????
else
????????????????
{
????????????????????pregkey.SetValue(
"撥號名字對應鍵值",?key,?RegistryValueKind.Binary);
????????????????????
//激活代理設置
????????????????????InternetSetOption(0,?39,?IntPtr.Zero,?0);
????????????????????InternetSetOption(
0,?37,?IntPtr.Zero,?0);
????????????????????webBrowser1.Navigate(txtweb.Text,?
false);
????????????????????webBrowser1.Refresh();
????????????????????
????????????????}


????????}

}

方法3: 使用c#自帶的 webproxy類,使用這種方法可以獲得目標網站的響應,但我不會把這種響應用IE反饋出來,有高手幫個忙么?
網上的代碼說是MSDN的:
????HttpWebRequest?myWebRequest=(HttpWebRequest)WebRequest.Create(" http://www.microsoft.com"/);?
????WebProxy?myProxy=new?WebProxy();?
????//?Obtain?the?'Proxy'?of?the??Default?browser.???
???? myProxy=(WebProxy)myWebRequest.Proxy;?這行我編譯不通過
????//?Print?the?Proxy?Url?to?the?console.?
????Console.WriteLine("/nThe?actual?default?Proxy?settings?are?{0}",myProxy.Address);?
????try?
????{?
????Console.WriteLine("/nPlease?enter?the?new?Proxy?Address?that?is?to?be?set:");?
????Console.WriteLine("(Example: http://myproxy.example.com:port/)");?
????string?proxyAddress;?
????proxyAddress?=Console.ReadLine();?
????if(proxyAddress.Length>0)?

????{?
????Console.WriteLine("/nPlease?enter?the?Credentials?");?
????Console.WriteLine("Username:");?
????string?username;?
????username?=Console.ReadLine();?
????Console.WriteLine("/nPassword:");?
????string?password;?
????password?=Console.ReadLine();?
????//?Create?a?new?Uri?object.?
????Uri?newUri=new?Uri(proxyAddress);?
????//?Associate?the?newUri?object?to?'myProxy'?object?so?that?new?myProxy?settings?can?be?set.?
????myProxy.Address=newUri;?
????//?Create?a?NetworkCredential?object?and?associate?it?with?the?Proxy?property?of?request?object.?
????myProxy.Credentials=new?NetworkCredential(username,password);?
????myWebRequest.Proxy=myProxy;?
????}?
????Console.WriteLine("/nThe?Address?of?the??new?Proxy?settings?are?{0}",myProxy.Address);?
????HttpWebResponse?myWebResponse=(HttpWebResponse)myWebRequest.GetResponse();

我改了下:
????

????????????HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.123cha.com");
??????????? WebProxy myProxy = new WebProxy("代理地址", true);
??????????? try
??????????? {
???????????????
??????????????? Console.WriteLine("/nThe Address of the? new Proxy settings are {0}", myProxy.Address);
??????????????? HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
??????????????
??????????????? webBrowser1.DocumentStream = myWebResponse.GetResponseStream();
?????????????

??????????? }
??????????? catch { }


本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388880.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388880.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388880.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C MySQL讀寫分離連接串_Mysql讀寫分離

一 什么是讀寫分離MySQL Proxy最強大的一項功能是實現“讀寫分離(Read/Write Splitting)”。基本的原理是讓主數據庫處理事務性查詢&#xff0c;而從數據庫處理SELECT查詢。數據庫復制被用來把事務性查詢導致的變更同步到集群中的從數據庫。當然&#xff0c;主服務器也可以提供…

golang 編寫的在線redis 內存分析工具 rma4go

redis 內存分析工具 rma4go redis是一個很有名的內存型數據庫&#xff0c;這里不做詳細介紹。而rma4go (redis memory analyzer for golang) 是一個redis的內存分析工具&#xff0c;這個工具的主要作用是針對運行時期的redis進行內存的分析&#xff0c;統計redis中key的分布情…

從Jupyter Notebook到腳本

16 Aug: My second article: From Scripts To Prediction API8月16日&#xff1a;我的第二篇文章&#xff1a; 從腳本到預測API As advanced beginners, we know quite a lot: EDA, ML concepts, model architectures etc…… We can write a big Jupyter Notebook, click “Re…

【EasyNetQ】- 使用Future Publish調度事件

許多業務流程要求在將來某個日期安排事件。例如&#xff0c;在與客戶進行初次銷售聯系后&#xff0c;我們可能希望在將來的某個時間安排跟進電話。EasyNetQ可以通過其Future Publish功能幫助您實現此功能。例如&#xff0c;這里我們使用FuturePublish擴展方法來安排未來一個月的…

Java這些多線程基礎知識你會嗎?

0、并發和并行、進程核線程、多進程和多線程的區別&#xff1a; &#xff08;這里的時間和時刻上的概念同物理上的一樣&#xff09; 并發&#xff1a;在一段時間內多個任務同時執行&#xff0c;或者說是在一段很短的時間內可以執行多條程序指令&#xff0c;微觀上看起來好像是可…

MySQL set names 命令_mysql set names 命令和 mysql 字符編碼問題

先看下面的執行結果&#xff1a;(rootlocalhost)[(none)]mysql>show variables like character%;---------------------------------------------------------------------------------------| Variable_name | Value |---------------------------------------------------…

設置Proxy Server和SQL Server實現數據庫安全

首先&#xff0c;我們需要了解一下SQL Server在WinSock上定義協議的步驟&#xff1a; 1. 在”啟動”菜單上&#xff0c;指向”程序/Microsoft Proxy Server”&#xff0c;然后點擊”Microsoft Management Console”。 2. 展開”Internet Information Service”,再展開運行Proxy…

Python django解決跨域請求的問題

解決方案 1.安裝django-cors-headers pip3 install django-cors-headers 2.配置settings.py文件 INSTALLED_APPS [...corsheaders&#xff0c;...] MIDDLEWARE_CLASSES (...corsheaders.middleware.CorsMiddleware,django.middleware.common.CommonMiddleware, # 注意順序...…

加勒比海兔_加勒比海海洋物種趨勢

加勒比海兔Ok, here’s a million dollar question: is the Caribbean really dying? Or, more specifically, are marine species found on Caribbean reefs becoming less abundant?好吧&#xff0c;這是一個百萬美元的問題&#xff1a;加勒比海真的死了嗎&#xff1f; 或者…

mysql 查出相差年數_MySQL計算兩個日期相差的天數、月數、年數

MySQL自帶的日期函數TIMESTAMPDIFF計算兩個日期相差的秒數、分鐘數、小時數、天數、周數、季度數、月數、年數&#xff0c;當前日期增加或者減少一天、一周等等。SELECT TIMESTAMPDIFF(類型,開始時間,結束時間)相差的秒數&#xff1a;SELECT TIMESTAMPDIFF(SECOND,1993-03-23 0…

tornado 簡易教程

引言 回想Django的部署方式 以Django為代表的python web應用部署時采用wsgi協議與服務器對接&#xff08;被服務器托管&#xff09;&#xff0c;而這類服務器通常都是基于多線程的&#xff0c;也就是說每一個網絡請求服務器都會有一個對應的線程來用web應用&#xff08;如Djang…

如果你的電腦是通過代理上網的.就要用端口映射

由于公網IP地址有限&#xff0c;不少ISP都采用多個內網用戶通過代理和網關路由共用一個公網IP上INTERNET的方法&#xff0c; 這樣就限制了這些用戶在自己計算機上架設個人網站&#xff0c;要實現在這些用戶端架設網站&#xff0c;最關鍵的一點是&#xff0c; 怎樣把多用戶的內網…

人口密度可視化_使用GeoPandas可視化菲律賓的人口密度

人口密度可視化GeoVisualization /菲律賓。 (GeoVisualization /Philippines.) Population density is a crucial concept in urban planning. Theories on how it affects economic growth are divided. Some claim, as Rappaport does, that an economy is a form of “spati…

Unity - Humanoid設置Bip骨骼導入報錯

報錯如下&#xff1a; 解決&#xff1a; 原因是biped骨骼必須按照Unity humanoid的要求設置&#xff0c;在max中設置如下&#xff1a; 轉載于:https://www.cnblogs.com/CloudLiu/p/10746052.html

python3openpyxl無法打開文件_Python3 處理excel文件(openpyxl庫)

openpyxl 介紹openpyxl是一個用于讀/寫 XLSX/XLSM/XLTX/XLTM文件的python庫。openpyxl(可讀寫excel表)專門處理Excel2007及以上版本產生的xlsx文件&#xff1b;2007一下的版本為xls后綴的文件&#xff0c;需要使用 xlrd和xlwt庫進行操作。雖然xlrd和xlwt也可以進行文件讀寫&…

Kubernetes - - k8s - v1.12.3 OpenLDAP統一認證

1&#xff0c;基本概念 為了方便管理和集成jenkins&#xff0c;k8s、harbor、jenkins均使用openLDAP統一認證。2&#xff0c;部署openLDAP 根據之前的文檔&#xff0c;openLDAP使用GFS進行數據持久化。下載對應的openLDAP文件git clone https://github.com/xiaoqshuo/k8s-clust…

給程序加殼

在內存中運行可執行程序&#xff0c;好處是可以給程序加殼&#xff0c;加密源程序&#xff0c;靜態反匯編無法獲得PE輸入節&#xff0c;但是因為運行后仍然是獨立的進程&#xff0c;所以沒辦法防止遠程線程注入&#xff0c;掛接API鉤子。 typedef IMAGE_SECTION_HEADER ( * PIM…

srpg 勝利條件設定_英雄聯盟獲勝條件

srpg 勝利條件設定介紹 (Introduction) The e-sports community has been growing rapidly in the past few years, and what used to be a casual pastime has morphed into an industry projected to generate $1.8 B in revenue by 2022. While there are many video games …

[Egret][文檔]遮罩

——遮罩的作用是指定一個顯示對象的可見區域&#xff0c;即這個顯示對象只在這個區域可見。 一、矩形遮罩 將一個矩形對象賦值給顯示對象的 mask 屬性。 shp.mask new egret.Rectangle(20,20,30,50); 【注】&#xff1a;這個矩形的坐標(20,20)和(30,50)是相對于被遮罩對象shp…

clob類型字段最大存儲長度_請教oracle的CLOB字段的最大長度?

CLOB和BLOB都是4G&#xff0c;而LONG ,LONG raw是舊時代的oracle二進制和長文本表示&#xff0c;將來會被廢棄。最長長度是2G.單位是Byte表中單個 LOB 字段 在 9i 版本中可保存 4GB 數據, 在 10g 版本中可保存多達 128TB 的數據.所以理論上是沒限制的ORACLE的數據類型-- ORAC…