C# 用 WebClient 模擬 IE 6.0 連線

C# 用 WebClient 模擬 IE 6.0 連線

  1. // 模擬 IE 6.0
  2. WebClient wc = new WebClient( );
  3. wc.Headers.Add ( "Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*" );
  4. wc.Headers.Add ( "Accept-Language", "zh-TW" );
  5. 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)" );
  6. Stream s = wc.OpenRead (url);
  7. StreamReader sr = new StreamReader(s, Encoding.UTF8 );
  8. string result = sr.ReadToEnd ( );

利用 WebClient 類別,並加入一些 Header 就可以騙過一些網站,讓 Web Server 信以為真是真正的使用者來訪,而非 Web Spider。