Cannot get request third time in a row - GetRequestStream() -

  • Thread starter Thread starter Piotrekk
  • Start date Start date
P

Piotrekk

Hi

I am uploading files to my ASP script one by one - from C#
application. Each time little upload form is created with
backgroundworker in it. When I try to upload THIRD file the worker is
stuck on getting requeststream.


WebRequest req = WebRequest.Create(url);
req.Method = "POST";

//Headers
req.ContentType = "multipart/form-data";
req.ContentLength = fileSize;
req.Headers.Add("Name",file.Name);
req.Headers.Add("Path", path);
req.Headers.Add("SessionID", session);

/// stuck here
Stream stream = req.GetRequestStream();

When I debug it on the server during third time, the Page_Load event
is not even called.
Do you have any idea what could that be?

Best Regards
PK
 
Piotrekk said:
I am uploading files to my ASP script one by one - from C#
application. Each time little upload form is created with
backgroundworker in it. When I try to upload THIRD file the worker is
stuck on getting requeststream.


WebRequest req = WebRequest.Create(url);
req.Method = "POST";

//Headers
req.ContentType = "multipart/form-data";
req.ContentLength = fileSize;
req.Headers.Add("Name",file.Name);
req.Headers.Add("Path", path);
req.Headers.Add("SessionID", session);

/// stuck here
Stream stream = req.GetRequestStream();

When I debug it on the server during third time, the Page_Load event
is not even called.
Do you have any idea what could that be?

Yes. Chances are you're not closing the response, which means the
connection to the server is left up, and you're only (by default)
allowed two connections to any one server.

Where you fetch the response, put it in a "using" statement and chances
are it'll all start working with no issues.
 
Dear Jon. I'm not using response in my connection. Here is the entire
backgroundworker code:


string url = String.Concat(this.url);
long fileSize = file.Length;

WebRequest req = WebRequest.Create(url);
req.Method = "POST";

//Headers
req.ContentType = "multipart/form-data";
req.ContentLength = fileSize;
req.Headers.Add("Name",file.Name);
req.Headers.Add("Path", path);
req.Headers.Add("SessionID", session);

Stream stream = req.GetRequestStream();

using (BinaryWriter writer = new BinaryWriter(stream))
{
FileStream fs = new FileStream(file.FullName,
FileMode.Open);

using (BinaryReader reader = new BinaryReader(fs))
{
int i = 0;
long total = 0;

byte[] buffer = new byte[32768];

while (((i = reader.Read(buffer,
0,buffer.Length)) > 0) && !Stop)
{
writer.Write(buffer,0,i);
total += i;
uploadWorker.ReportProgress((int)(total *
100 / fileSize));
}
}
}
 
Piotrekk said:
I'm not using response in my connection.

If the server is working at all, there is always a response for each
request. Even an error message (for example http 404) is a response.
 
Back
Top