2012-02-29 69 views

回答

5

您可以使用System.Net.WebClient類訪問URL。

using (WebClient client = new WebClient()) 
{ 
    client.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0)" + 
    " (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; 

    // Download data. 
    byte[] arr = client.DownloadData("http://www.yourserver.com/"); // url for .ashx file 

    // Write values. 
    Console.WriteLine("--- WebClient result ---"); 
    Console.WriteLine(arr.Length); 

} 

在這裏您可以找到MSDN documentation

相關問題