我想知道您是否可以帮助我解决我遇到的错误。我创建了一个 HTTP 管理器,可以帮助我处理来自网站的 POST/GET 数据。直到最近,当我尝试将两者混合使用时,它一直运行良好。第一个循环一切正常,第二个循环挂在 HttpWebRequest.GetRequestStream() 上。我已经阅读了整个网络,并没有找到真正的解决方案。以下是获取/接收的代码块:
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] buffer = encoding.GetBytes(_PostData);
_HttpWebRequest = (HttpWebRequest)WebRequest.Create(_FetchUrl);
_HttpWebRequest.Credentials = _Credentials;
_HttpWebRequest.Method = _RequestType.ToString();
_HttpWebRequest.ContentType = "application/x-www-form-urlencoded";
_HttpWebRequest.ContentLength = buffer.Length;
_HttpWebRequest.UserAgent = userAgent;
_HttpWebRequest.CookieContainer = _CookieContainer;
_HttpWebRequest.KeepAlive = false;
_HttpWebRequest.AllowAutoRedirect = _AllowAutoRedirect;
_HttpWebRequest.AutomaticDecompression = DecompressionMethods.GZip;
_HttpWebRequest.ServicePoint.Expect100Continue = false;
if (_RequestType.Equals(RequestTypes.POST))
{
// Write POST
Stream reqStream = _HttpWebRequest.GetRequestStream();
{
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Flush();
reqStream.Close();
}
}
和回应:
HttpWebResponse httpWebResponse = (HttpWebResponse)_HttpWebRequest.GetResponse();
{
Stream responseStream = httpWebResponse.GetResponseStream();
{
if (_UseGzip)
{
if (httpWebResponse.ContentEncoding.ToLower().Contains("gzip"))
{
responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
}
else
{
responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
}
}
if (responseStream != null)
{
StreamReader streamReader = new StreamReader(responseStream);
{
try
{
_PageContent = streamReader.ReadToEnd();
}
finally
{
streamReader.Close();
responseStream.Close();
httpWebResponse.Close();
}
}
}
else
{
_PageContent = string.Empty;
}
}
}
_HttpWebRequest.Abort();
谁能看到我的代码挂起的任何缺陷?所有流都被关闭,我已将允许的连接设置为超过 100,我不明白为什么会这样。