473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
Jun 27 '08 #1
4 3438
Piotrekk <Pi*************@gmail.comwrote:
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 - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #2
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
Jun 27 '08 #3
req.GetResponse().Close() did the work. Thank you.
Jun 27 '08 #4
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
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Guettler | last post by:
Hi, I think it would be good, if the current time would be in the traceback. This would make it easier to read logfiles with tracebacks of python scripts. I know that I can write a custom...
3
by: Amal Ismail | last post by:
hello this is the third time i inquire aboutthe same thing and none answer me !! .. hope to find help here i'm using ASP.NET Mobile web application using c# And i'm facing a problem , i use...
2
by: Bruce W.1 | last post by:
How long will IE wait for a response to a http request before it times-out? Thanks for your help.
1
by: Hudson Mendes | last post by:
I'm not believing in results of many tests I did, but they justify this Post title. How may I setup my WebServices or ASPNET Processo to process more than one call per time??? Look: ...
0
by: Andrej | last post by:
hi, i have a java webservice which i would like to invoke from .net Application. i am able to generate the proxy class, but if i try to invoke the webservice i got an exception of type...
18
by: ***** charles | last post by:
Hi all, I have tried to learn C now several times before but gave up twice. I would like to learn GCC under Debian. Is there any good BEGINNER tutorials out there that will take me from the...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.