dz asp.net论坛中函数--根据Url获得源文件内容
程序员文章站
2022-11-23 18:10:22
需要引入命名空间:复制代码 代码如下:using system.net; using system.io;函数内容:复制代码 代码如下:///
需要引入命名空间:
using system.net;
using system.io;
函数内容:
/// <summary>
/// 根据url获得源文件内容
/// </summary>
/// <param name="url">合法的url地址</param>
/// <returns></returns>
public static string getsourcetextbyurl(string url)
{
webrequest request = webrequest.create(url);
request.timeout = 20000;//20秒超时
webresponse response = request.getresponse();
stream resstream = response.getresponsestream();
streamreader sr = new streamreader(resstream);
return sr.readtoend();
}
复制代码 代码如下:
using system.net;
using system.io;
函数内容:
复制代码 代码如下:
/// <summary>
/// 根据url获得源文件内容
/// </summary>
/// <param name="url">合法的url地址</param>
/// <returns></returns>
public static string getsourcetextbyurl(string url)
{
webrequest request = webrequest.create(url);
request.timeout = 20000;//20秒超时
webresponse response = request.getresponse();
stream resstream = response.getresponsestream();
streamreader sr = new streamreader(resstream);
return sr.readtoend();
}
下一篇: PHP实现文件上传操作和封装