Setting Connection: Keep-Alive

1,968 views
Skip to first unread message

Tom Fleischer

unread,
Apr 4, 2012, 9:40:20 AM4/4/12
to RestSharp
I am attempted to set the Connection header to Keep-Alive, but I get a
null reference exception when I use AddHeader() or AddParameter():

restRequest.AddHeader("Connection", "Keep-Alive");

restRequest.AddParameter("Connection", "Keep-Alive",
ParameterType.HttpHeader);


Any thoughts on this? Basically I am seeing some performance problems
doing many consecutive posts using RestSharp, and I am looking for
ways to tweak this.

Any help would be greatly appreciated, thanks again.

-Tom

John Sheehan

unread,
Apr 4, 2012, 7:10:44 PM4/4/12
to rest...@googlegroups.com
Where's the null reference exception being thrown?

Prabhendu Pandey

unread,
May 11, 2015, 11:03:50 AM5/11/15
to rest...@googlegroups.com
Hi,

I am also facing similar error.
The error is while executing request...says that cannot keepAlive or close connection using addheader..

I need to set this parameter to false and my API uses Restsharp..any workaround for this?

Adam Meily

unread,
May 15, 2015, 1:13:00 PM5/15/15
to rest...@googlegroups.com
I do not understand why it is currently impossible to disable persistent connections. I am currently using RestSharp in a production project and now I have to switch to a different framework. From the questions that have been asked on SO and here, this problem has been around for some time. In my opinion, this framework is garbage, and people wanting a truly configurable REST API framework should look elsewhere.

The exact problem is that RestSharp is reusing closed sockets. When this occurs, the RequestResponse.ErrorException is:

System.Net.WebException: The underlying connection was closed: An unexpected error
occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An
 established connection was aborted by the software in your host machine. --->
System.Net.Sockets.SocketException: An established connection was aborted by the software in your host
machine
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean
probeRead)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at RestSharp.Http.GetRawResponse(HttpWebRequest request)
   at RestSharp.Http.GetResponse(HttpWebRequest request)

Prabhendu Pandey

unread,
May 15, 2015, 1:18:03 PM5/15/15
to rest...@googlegroups.com
They have not provided any property for keepAlive feature which can be used...
I used the basic httpwebrequest to access keepAlive header...but I had another issue which was not solved by even keeping KeepAlive as false..

:) Its tough though...restsharp works brilliantly for GET and sometimes for POST, but its killing me for implementing PUT using body request...
Reply all
Reply to author
Forward
0 new messages