解决方案 »
- c#怎么在一个类里调用另外一个类的变量
- 在vn ent中,如何利用treeview和listview实习资源管理界面,
- C#如何输入格式化的XML文本
- 如何使用FileUploaderAJAX上传大文件
- C# Process类 执行bat文件 显示不出信息
- the Port " name " does not exist 串口问题
- 求大神给讲讲EnumChildWindows与回调函数的用法。
- 谁有A C# Application from Inspiration to Implementation的完整代码
- 求教 js怎样取json的值
- 菜鸟问简单的问题:谁有现成的代码(win form的):如何把数据库中的问题显示在treeview中?
- Chart 控件 如何显示横滚动条 CursorX 部分放大
- winform程序求解啊
public static string DownloadHtmlPage(string pageUrl, Encoding encoding, string requestMethod, int timeOut)
{
string value = string.Empty;
HttpWebResponse response = null;
Stream data = null;
StreamReader sr = null;
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(pageUrl);
request.Method = requestMethod;
request.ServicePoint.Expect100Continue = false;
//是否使用 Nagle 不使用 提高效率
request.ServicePoint.UseNagleAlgorithm = false;
//最大连接数
request.ServicePoint.ConnectionLimit = 65500;
//数据是否缓冲 false 提高效率
request.AllowWriteStreamBuffering = false;
request.UserAgent = UserAgent;
request.KeepAlive = true;
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.Headers.Add("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3");
request.Headers.Add("Accept-Encoding:gzip,deflate,sdch");
request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
request.Headers.Add("Cache-Control", "max-age=0");
if (timeOut != -1) request.Timeout = timeOut;
response = (HttpWebResponse)request.GetResponse();
data = response.GetResponseStream();
sr = new StreamReader(data, encoding);
string str;
StringBuilder source = new StringBuilder();
while ((str = sr.ReadLine()) != null)
source.Append(str).Append("\r\n");
value = source.ToString();
}
catch (WebException e)
{
//MessageBox.Show(e.Message);
}
finally
{
if (sr != null) sr.Close();
if (data != null) data.Close();
if (response != null) response.Close();
}
return value;
}
第一次运行会超时的问题不太懂,有没有人有经验,是为啥?
win7 32位,vs2008。