小编Pau*_*ham的帖子

有谁知道为什么我收到HttpWebRequest超时?

我想知道你是否可以帮我解决我遇到的一个错误.我有一个我创建的HTTP管理器,可以帮助我处理来自网站的POSTing/GETing数据.直到最近,当我尝试使用两者的混合物时,它一直工作正常.第一个循环循环一切正常,在第二个循环上它挂起在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();
    }
}
Run Code Online (Sandbox Code Playgroud)

和响应:

HttpWebResponse httpWebResponse = (HttpWebResponse)_HttpWebRequest.GetResponse();
{
  Stream responseStream = httpWebResponse.GetResponseStream();
  {
    if (_UseGzip)
    {
      if (httpWebResponse.ContentEncoding.ToLower().Contains("gzip"))
      {
        responseStream = …
Run Code Online (Sandbox Code Playgroud)

c# timeout httprequest hang

10
推荐指数
1
解决办法
6579
查看次数

标签 统计

c# ×1

hang ×1

httprequest ×1

timeout ×1