2011-01-26 58 views
0

我需要申請一系列頁面,想,如果你是用Ajax做從服務器代碼做,我可以做?謝謝請求與服務器代碼的頁面

+0

http://meta.stackexchange.com/questions/18584/how-to-ask-a-smart-question and http://msmvps.com/blogs/jon_skeet/archive/2010/08/ 29/writing-the-perfect-question.aspx – Will 2011-01-26 20:47:05

回答

2

您正在尋找的WebClient類。

+0

+1。只是爲了幫助:`var pageContents = new WebClient()。DownloadString(「http://example.com」);` – orip 2011-01-26 21:01:05

0

使用此c#函數。使用System.Net添加;頁面頂部。

private string MakeWebRequest(string url) { 
    string retValue = String.Empty; 
    try 
    { 
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
     HttpWebResponse response = null; 
     request.Method = "GET"; 

     response = (HttpWebResponse)request.GetResponse(); 
     StreamReader stReader = new StreamReader(response.GetResponseStream()); 

     retValue = stReader.ReadToEnd(); 

     stReader.Close(); 
     response.Close(); 

     stReader.Dispose(); 
     stReader = null; 
     response = null; 
     request = null; 
    } 
    catch (Exception ex) { 

    } 


    return retValue; 
}