用StreamReader读取服务器端文本文件,或远程网页
用StreamReader读取服务器端文本文件,或远程网页
放在WebService中,返回字符串,使得ajax解析方便。
[WebMethod]
public string getFile(string fn){
string str="";
string line="";
StreamReader sr = new StreamReader(Server.MapPath("data\\"+fn));
while ((line = sr.ReadLine()) != null)
{
str+=line+"\n";
}
return str;
}
[WebMethod]
public string getPage(string url){
string str="";
WebRequest myRequest = WebRequest.Create(url);
WebResponse myResponse = myRequest.GetResponse();
Stream s=myResponse.GetResponseStream();
StreamReader sr=new StreamReader(s);
str=sr.ReadToEnd();
return str;
}
放在WebService中,返回字符串,使得ajax解析方便。
[WebMethod]
public string getFile(string fn){
string str="";
string line="";
StreamReader sr = new StreamReader(Server.MapPath("data\\"+fn));
while ((line = sr.ReadLine()) != null)
{
str+=line+"\n";
}
return str;
}
[WebMethod]
public string getPage(string url){
string str="";
WebRequest myRequest = WebRequest.Create(url);
WebResponse myResponse = myRequest.GetResponse();
Stream s=myResponse.GetResponseStream();
StreamReader sr=new StreamReader(s);
str=sr.ReadToEnd();
return str;
}
posted on 2005-09-11 14:49 civ3's .NET studying 阅读(659) 评论(0) 编辑 收藏 举报