获取远程网页的内容之一(downmoon原创)
一、本机直接上网时:
获取指定远程网页内容#region 获取指定远程网页内容
复制代码 代码如下:
/**//// <summary>
/// 获取指定远程网页内容
/// </summary>
/// <param name="strUrl">所要查找的远程网页地址</param>
/// <param name="timeout">超时时长设置,一般设置为8000</param>
/// <param name="enterType">是否输出换行符,0不输出,1输出文本框换行</param>
/// <param name="EnCodeType">编码方式</param>
/// <returns></returns>
/// 也可考虑 static string
public string GetRequestString(string strUrl,int timeout,int enterType,Encoding EnCodeType)
...{
string strResult;
try
...{
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl) ;
myReq.Timeout = timeout;
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream () ;
StreamReader sr = new StreamReader(myStream , EnCodeType);
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
...{
strBuilder.Append(sr.ReadLine());
if(enterType==1)
...{
strBuilder.Append(" ");
}
}
strResult = strBuilder.ToString();
}
catch(Exception err)
...{
strResult = "请求错误:" + err.Message;
}
return strResult ;
}
#endregion
二:通过域环境代理上网时这样就不行了! 下篇文章分解,呵呵
一、本机直接上网时:
获取指定远程网页内容#region 获取指定远程网页内容
复制代码 代码如下:
/**//// <summary>
/// 获取指定远程网页内容
/// </summary>
/// <param name="strUrl">所要查找的远程网页地址</param>
/// <param name="timeout">超时时长设置,一般设置为8000</param>
/// <param name="enterType">是否输出换行符,0不输出,1输出文本框换行</param>
/// <param name="EnCodeType">编码方式</param>
/// <returns></returns>
/// 也可考虑 static string
public string GetRequestString(string strUrl,int timeout,int enterType,Encoding EnCodeType)
...{
string strResult;
try
...{
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl) ;
myReq.Timeout = timeout;
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream () ;
StreamReader sr = new StreamReader(myStream , EnCodeType);
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
...{
strBuilder.Append(sr.ReadLine());
if(enterType==1)
...{
strBuilder.Append(" ");
}
}
strResult = strBuilder.ToString();
}
catch(Exception err)
...{
strResult = "请求错误:" + err.Message;
}
return strResult ;
}
#endregion
二:通过域环境代理上网时这样就不行了! 下篇文章分解,呵呵
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“获取远程网页的内容之一(downmoon原创)”评论...