B
Basel
Hi All!
My code issues Http POST requests in a loop using HttpWebRequest, I set
one unique ConnectionGroupName, and I expected from the client to open
one underlying persistent connection for all the requests I generate.
This is the code:
public static void Main()
{
for(int i=0;i<100000;i++)
PostRequest()
}
static public void PostRequest()
{
ASCIIEncoding encoding=new ASCIIEncoding();
byte[] data = encoding.GetBytes("This is a string");
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/cgi");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
}
But the actual result is that on each request the client (or the
server?) closes the connection and opens a new one.
does the code above supposed to leave the connection opened?
I see that myStream.Close() method description is:
" Closes the current stream and releases any resources (such as sockets
and file handles) associated with the current stream."
So maybe this method closes the connection?
Or in this case, the server closes the connection?
Basel
My code issues Http POST requests in a loop using HttpWebRequest, I set
one unique ConnectionGroupName, and I expected from the client to open
one underlying persistent connection for all the requests I generate.
This is the code:
public static void Main()
{
for(int i=0;i<100000;i++)
PostRequest()
}
static public void PostRequest()
{
ASCIIEncoding encoding=new ASCIIEncoding();
byte[] data = encoding.GetBytes("This is a string");
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/cgi");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
}
But the actual result is that on each request the client (or the
server?) closes the connection and opens a new one.
does the code above supposed to leave the connection opened?
I see that myStream.Close() method description is:
" Closes the current stream and releases any resources (such as sockets
and file handles) associated with the current stream."
So maybe this method closes the connection?
Or in this case, the server closes the connection?
Basel