获取远程网页的内容之一(downmoon原创)
一、本机直接上网时:
获取指定远程网页内容#region获取指定远程网页内容
复制代码 代码如下:
/**////<summary>
///获取指定远程网页内容
///</summary>
///<paramname="strUrl">所要查找的远程网页地址</param>
///<paramname="timeout">超时时长设置,一般设置为8000</param>
///<paramname="enterType">是否输出换行符,0不输出,1输出文本框换行</param>
///<paramname="EnCodeType">编码方式</param>
///<returns></returns>
///也可考虑staticstring
publicstringGetRequestString(stringstrUrl,inttimeout,intenterType,EncodingEnCodeType)
...{
stringstrResult;
try
...{
HttpWebRequestmyReq=(HttpWebRequest)HttpWebRequest.Create(strUrl);
myReq.Timeout=timeout;
HttpWebResponseHttpWResp=(HttpWebResponse)myReq.GetResponse();
StreammyStream=HttpWResp.GetResponseStream();
StreamReadersr=newStreamReader(myStream,EnCodeType);
StringBuilderstrBuilder=newStringBuilder();
while(-1!=sr.Peek())
...{
strBuilder.Append(sr.ReadLine());
if(enterType==1)
...{
strBuilder.Append("");
}
}
strResult=strBuilder.ToString();
}
catch(Exceptionerr)
...{
strResult="请求错误:"+err.Message;
}
returnstrResult;
}
#endregion
二:通过域环境代理上网时这样就不行了!下篇文章分解,呵呵