http - Using HttpWebRequest, Keep-alive not working for many similar requests to localhost -
i'm using httpwebrequest
send many sync requests same http url on localhost, , need re-use tcp connections prevent ephemeral port depletion.
but don't seem able keep-alive working.
here's code make http request:
var request = (httpwebrequest) webrequest.create(url); httpwebresponse response = null; request.method = "get"; request.keepalive = true; try { response = (httpwebresponse) request.getresponse(); // ... } catch (exception e) { // ... } { if (response != null) { response.close(); } }
i call above code many times in loop. requests successful, , return ok status code (200), running netstat -ano
reveals there many many connections in time_wait
state, expect re-use single connection.
i tried calling both iis express server on localhost (default asp.net mvc application) , weblogic application, same result.
i tried httpclient
.net 4.5.
this results in running out of ephemeral ports.
is there wrong i'm doing? how can make .net re-use tcp connections?
try response.dispose(); instead of response.close();
Comments
Post a Comment