gpt4 book ai didi

c# - HttpWebRequest.GetResponse : "The underlying connection was closed: An unexpected error occurred on a receive."

转载 作者:行者123 更新时间:2023-11-30 17:21:42 28 4
gpt4 key购买 nike

我编写了一个 C# Windows 服务(.NET Framework 3.5、C# 3.0),它将文件和 HTML 表单信息发布到远程服务器,然后将 XML 服务器响应存储在数据库中。这是相关代码的主要部分:

    HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest;

request.ProtocolVersion = HttpVersion.Version10;
request.KeepAlive = false;
request.Timeout = 600000;
request.ReadWriteTimeout = 600000;
request.Method = "POST";
request.ContentType = contentType;
request.UserAgent = userAgent;
request.CookieContainer = new CookieContainer();
request.ContentLength = formData.Length;

using (Stream requestStream = request.GetRequestStream())
{
// Push it out there
requestStream.Write(formData, 0, formData.Length);
requestStream.Close();
}

return request.GetResponse() as HttpWebResponse;

我的服务适用于所有小文件,但当我尝试发送较大文件 (8-9 MB) 时出现以下错误。

    The underlying connection was closed: An unexpected error occurred on a receive.

我使用 Fiddler 查看了传出请求,并能够收集到以下信息:

    HTTP/1.1 504 Fiddler - Receive Failure
Content-Type: text/html
Connection: close
Timestamp: 12:25:04.067

ReadResponse() failed: The server did not return a response for this request.

失败发生在我调用 request.GetResponse() 后约 7 分钟。有什么办法可以确定是谁关闭了连接?还有什么我应该尝试解决这个问题的吗?提前致谢!

最佳答案

既然你提到它适用于小文件,而不是更大的文件,我建议检查服务器上的最大文件上传大小。我相信默认值是 4mb。 http://support.microsoft.com/kb/295626

编辑:注意到上面的链接有点过时了。这是 iis7 的一个:http://www.cyprich.com/2008/06/19/fixing-file-upload-size-limit-in-iis-7/

关于c# - HttpWebRequest.GetResponse : "The underlying connection was closed: An unexpected error occurred on a receive.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3197010/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com