protected void Page_Load(object sender, EventArgs e)
{
string aa= httpRequest("http://www.baidu.com");
}
//httP请求
public static string httpRequest(string url)
{
WebRequest req = WebRequest.Create(url);
WebResponse res = req.GetResponse(); // GetResponse blocks until the response arrives
Stream ReceiveStream = res.GetResponseStream(); // Read the stream into a string
StreamReader sr = new StreamReader(ReceiveStream);
string resultstring = sr.ReadToEnd();
return resultstring;
}
(摘自:http://www.cnblogs.com/tuyile006/archive/2008/11/14/1333632.html)
本文提供了一个简单的示例,展示了如何使用C#进行HTTP请求,并解析响应内容为字符串。通过实例代码,读者可以了解如何获取外部网页的数据。
1640

被折叠的 条评论
为什么被折叠?



