一、本机直接上网时:
#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("/r/n");
}
}
strresult = strbuilder.tostring();
}
catch(exception err)
{
strresult = "请求错误:" + err.message;
}
return strresult ;
}
#endregion
二:通过域环境代理上网时这样就不行了! 下篇文章分解,呵呵!
新闻热点
疑难解答
图片精选