public struct Struct_INTERNET_PROXY_INFO接著在視窗讀取 ( Form1_Load ) 時,要如此呼叫
{
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 Form1_Load(object sender, EventArgs e)執行後,如果要驗證是否為代理伺服器進入 http://www.google.com.tw/,就可在搜尋引擎上鍵入 "What is my ip",找到 http://www.whatismyip.com/,點擊進去,就會看到自己目前的 ip,而我這範例執行後,畫面如下如此一來設定完成,收工。
{
RefreshIESettings("216.59.17.116:8080");
webBrowser1.Navigate("http://www.google.com.tw/");
}
回目錄
回首頁
沒有留言 :
張貼留言