2011-01-26 59 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; 
}