PC Review


Reply
Thread Tools Rate Thread

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

 
 
Piotrekk
Guest
Posts: n/a
 
      23rd Jun 2008
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
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      23rd Jun 2008
Piotrekk <(E-Mail Removed)> wrote:
> 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.

--
Jon Skeet - <(E-Mail Removed)>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
 
Reply With Quote
 
Piotrekk
Guest
Posts: n/a
 
      23rd Jun 2008
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));
}
}
}


>
> Where you fetch the response, put it in a "using" statement and chances
> are it'll all start working with no issues.
>
> --
> Jon Skeet - <sk...@pobox.com>
> Web site:http://www.pobox.com/~skeet*
> Blog:http://www.msmvps.com/jon_skeet
> C# in Depth:http://csharpindepth.com


 
Reply With Quote
 
Piotrekk
Guest
Posts: n/a
 
      23rd Jun 2008
req.GetResponse().Close() did the work. Thank you.
 
Reply With Quote
 
Göran Andersson
Guest
Posts: n/a
 
      23rd Jun 2008
Piotrekk wrote:
> 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.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GetRequestStream blocks Mike Markiewicz Microsoft C# .NET 3 4th Jun 2006 07:43 PM
Stream requestStream = request.GetRequestStream(); Error 401 no autorizado Luis Esteban Valencia Microsoft ASP .NET 0 7th Jul 2005 05:53 PM
Appointment Request time resets to current time Dan Microsoft Outlook Discussion 0 23rd Feb 2005 10:56 AM
GetRequestStream() Questions Microsoft ASP .NET 0 11th Jan 2004 03:25 AM
meeting request time and time stamp one hour off hoot Microsoft Outlook Interoperability 1 24th Sep 2003 10:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 AM.