- 积分
- 10954
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
发表于 2014-12-31 10:48:03
|
显示全部楼层
DateTime st = DateTime.Now;
StringBuilder sbHtml = new StringBuilder("");
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://yzgsj.gov.cn/baweb/show/sj/JggsServlet");
HttpWebResponse httpResp = null;
try
{
httpReq.AllowAutoRedirect = true;
httpReq.Timeout = 1000;
httpReq.Method = "POST";
httpReq.KeepAlive = true;
httpReq.ContentType = "application/x-www-form-urlencoded";
CookieContainer myCookieContainer = new CookieContainer();
httpReq.CookieContainer = myCookieContainer;
byte[] bytesData1 = System.Text.Encoding.GetEncoding("utf-8").GetBytes("pageNo=1&pageSize=20");
httpReq.ContentLength = bytesData1.Length;
Stream postStream1 = httpReq.GetRequestStream();
postStream1.Write(bytesData1, 0, bytesData1.Length);
httpResp = (HttpWebResponse)httpReq.GetResponse();
MessageBox.Show("耗时:" + (DateTime.Now - st).TotalSeconds + "秒,反馈状态:" + httpResp.StatusDescription);
StreamReader reader = new StreamReader(httpResp.GetResponseStream(), Encoding.GetEncoding("utf-8"));
sbHtml.Append(reader.ReadToEnd());
string responseHeader = httpResp.Headers.ToString();
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show("耗时:" + (DateTime.Now - st).TotalSeconds + "秒,反馈状态:" +ex.Message);
}
timeout设置后,必然是在设定的时间后有状态提示。你没处理好而已。 |
|