|
楼主 |
发表于 2014-12-31 10:33:06
|
显示全部楼层
好的,我试过了,确实没有在3秒的时候返回,目前是在3秒后才返回StatusCode=200,代码:
StringBuilder sbHtml = new StringBuilder("");
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://yzgsj.gov.cn/baweb/show/sj/JggsServlet");
HttpWebResponse httpResp = null;
try
{
httpReq.AllowAutoRedirect = cbxAllowRedirect.Checked;
httpReq.Timeout = 3000;
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();
StreamReader reader = new StreamReader(httpResp.GetResponseStream(), Encoding.GetEncoding("utf-8"));
sbHtml.Append(reader.ReadToEnd());
string responseHeader = httpResp.Headers.ToString();
reader.Close();
//txtPostedPageInfo.Text = responseHeader + "\r\n-------------\r\n" + sbHtml.ToString();
//wbsrPostedPageInfo.DocumentText = sbHtml.ToString();
return SbHtml.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
if (httpResp != null)
{
httpResp.Close();
httpReq.Abort();
}
} |
|