我需要请求一系列页面,并希望从服务器代码中执行,就像使用Ajax一样,我能做到吗?,谢谢
答案 0 :(得分:2)
您正在寻找WebClient
课程。
答案 1 :(得分: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;
}