C# 用 WebClient 模擬 IE 6.0 連線
-
// 模擬 IE 6.0
-
WebClient wc = new WebClient ( );
-
wc.Headers.Add ( "Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*" );
-
wc.Headers.Add ( "Accept-Language", "zh-TW" );
-
wc.Headers.Add ( "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" );
-
Stream s = wc.OpenRead (url);
-
StreamReader sr = new StreamReader (s, Encoding. UTF8 );
-
string result = sr.ReadToEnd ( );
|
利用 WebClient 類別,並加入一些 Header 就可以騙過一些網站,讓 Web Server 信以為真是真正的使用者來訪,而非 Web Spider。