I want to get some data using HttpWebRequest (GET):
var request = (HttpWebRequest)WebRequest.Create(myUri);
request.Timeout = 5 * 60 * 1000;
request.ReadWriteTimeout = 5 * 60 * 1000;
var response = request.GetResponse();
Unfortunately, computing on the server can take two or more minutes. Therefore, between sending the header and receiving data in the response stream, the socket connection is idle.
With curl or browser, the answer finally comes. But when using HttpWebRequest I always get an exception after 90 seconds:
System.AggregateException: One or more errors occurred. --->
System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure --->
System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. --->
System.Net.Sockets.SocketException: Connection reset by peer
When comparing TCP traffic in Wireshark between curl and HttpWebRequest, I noticed that curl is sending Keep-Alive TCP (ACK) packets. Unfortunately, even after turning on
ServicePointManager.SetTcpKeepAlive(true, 5 * 1000, 1000);
HttpWebRequest Keep-Alive Wireshark. ACK ( . ).
--no-keepalive, ( 90 ). , , , .
:
, GET , , API . , TCP Keep-Alive .Net