I wrote a Windows C # service (.NET Framework 3.5, C # 3.0) that sends files and HTML form information to a remote server, and then stores the XML server response in a database. Here is the main piece of relevant code:
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())
{
requestStream.Write(formData, 0, formData.Length);
requestStream.Close();
}
return request.GetResponse() as HttpWebResponse;
My service works correctly for all small files, but when I try to send larger files (8-9 MB), the following error occurs.
The underlying connection was closed: An unexpected error occurred on a receive.
I looked at the outgoing request using Fiddler and was able to get the following information:
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.
7 request.GetResponse(). , ? - , , ? !