473,657 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebResponse seems to hang

Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60 000);
HttpWebRequest
wReq=(HttpWebRe quest)WebReques t.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebRe sponse)wReq.Get Response();
MessageBox.Show ("Completed..." );
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.

Nov 17 '05 #1
3 4656
Nuno,

Just guessing, AFAIK does standard with http 1.1 a computer handles only 2
http requests in the same time. (AFAIK is this build in by the builders of
the operating systems, this is an agreement with Internet providers)

Cor
"Nuno Magalhaes" <nu************ @hotmail.com> schreef in bericht
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60 000);
HttpWebRequest
wReq=(HttpWebRe quest)WebReques t.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebRe sponse)wReq.Get Response();
MessageBox.Show ("Completed..." );
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.

Nov 17 '05 #2
Hi Nuno. Actually it does throw an exception, a System.Net.WebE xception
after 100 seconds (the default timeout for Web Responses).

It's being caused by not closing your resources. You need to close your
HttpWebResponse when you are done with it. Here is the modified code that
works.

HttpWebResponse wRes = null;

try
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60 000);
HttpWebRequest wReq=(HttpWebRe quest)
WebRequest.Crea te("http://pipa.inov.pt/cgi-bin/camera");

wRes =(HttpWebRespon se)wReq.GetResp onse();

MessageBox.Show ("Completed..." );

// Close the wRes object. Limited resources available.
wRes.Close();
wRes = null;
}
}
catch(System.Ex ception ex)
{
// Handle the exception appropriately
Debug.WriteLine (ex.ToString()) ;
}
finally
{
// Clean up the resource in case it wasn't cleaned up previously.
if ( wRes != null )
wRes.Close();
}

Hope this helps.
- Jason Bartosch

"Nuno Magalhaes" wrote:
Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60 000);
HttpWebRequest
wReq=(HttpWebRe quest)WebReques t.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebRe sponse)wReq.Get Response();
MessageBox.Show ("Completed..." );
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.

Nov 17 '05 #3
It actually helped. Thanks a lot.

Jason Bartosch wrote:
Hi Nuno. Actually it does throw an exception, a System.Net.WebE xception
after 100 seconds (the default timeout for Web Responses).

It's being caused by not closing your resources. You need to close your
HttpWebResponse when you are done with it. Here is the modified code that
works.

HttpWebResponse wRes = null;

try
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60 000);
HttpWebRequest wReq=(HttpWebRe quest)
WebRequest.Crea te("http://pipa.inov.pt/cgi-bin/camera");

wRes =(HttpWebRespon se)wReq.GetResp onse();

MessageBox.Show ("Completed..." );

// Close the wRes object. Limited resources available.
wRes.Close();
wRes = null;
}
}
catch(System.Ex ception ex)
{
// Handle the exception appropriately
Debug.WriteLine (ex.ToString()) ;
}
finally
{
// Clean up the resource in case it wasn't cleaned up previously.
if ( wRes != null )
wRes.Close();
}

Hope this helps.
- Jason Bartosch

"Nuno Magalhaes" wrote:
Hello,

In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60 000);
HttpWebRequest
wReq=(HttpWebRe quest)WebReques t.Create("http://pipa.inov.pt/cgi-bin/camera");

HttpWebResponse wRes=(HttpWebRe sponse)wReq.Get Response();
MessageBox.Show ("Completed..." );
}
}
The problem is: "It only completes 2 times...". Why doesn't it get
completed all the times I want... and why does it hangs (on the thread
of course) in GetResponse() method?

The strange thing is that when I try to access any of the wRes
properties it doesn't complete nothing at all. More: it doesn't give
any exceptions... nothing... it seems like the function evaporates to
nowhere.

Tried with different websites and all give the same problem... hangs up
at the 3rd time. I'm not seeing the complete message for the third time
in all types of webpages (static .html; .asp; etc...)

Thanks for any help,
Nuno Magalhaes.


Nov 17 '05 #4

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

Similar topics

0
2107
by: Denny Rue | last post by:
I’ve created VB code to download files from a web site through the use of HTTPWebRequest, HTTPWebResponse and BinaryReader. The HTTPWebRequest has a TimeOut property to limit how long it waits for a corresponding HTTPWebResponse. This works just fine. However, the timeout does not appear to apply to a BinaryReader created from the HTTPWebResponse. I’ve had instances where the procedures will hang indefinitely during the download. ...
0
10316
by: hlabbott | last post by:
Hi I'm having a problem displaying attachments correctly. I have messages with attachments stored on Exchange2000 and want to be able to click a hyperlink in my project like in OWA and see an attachment. Because it is stored on Exchange I have to set a username and password so I do a GET request. The data I get back seems to still be encoded - trying to open an excel file for example results in it trying to open it but an excel...
0
2912
by: Nathan | last post by:
This is a copy of a message at microsoft.public.dotnet.framework.clr: THE CODE: I'm using an HttpWebResponse object to send an HTTP POST to a Java server I have written and are running on the same machine (for dev and testing). Here is the C# code snippet: 1 string clientAddr = "http://127.0.0.1:22225/"; 2 try 3 { 4 webreq = (HttpWebRequest)WebRequest.Create( clientAddr );
2
2596
by: Noggin The Nog | last post by:
Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I get "The operation has timed-out". I'm simply trying to send an HTTP request querystring to a remote website and read back the single string it returns (OK/Not-Ok)! It seems such a simple thing to do, but I've been on this for hours now! Here's the code I'm trying: Dim myRequest As HttpWebRequest Dim myResponse As HttpWebResponse
2
2383
by: Nuno Magalhaes | last post by:
In pages that there is no content length, how does HttpWebResponse knows where the page ends? And what kind of objects/methods does it retrieve? Does it only retrieve the initial page without any images, i.e., does it only makes one "GET / HTTP/1.1\r\n\r\n"? Because I'm doing some projects on a webclient (to measure some statistic times) and the total bytes get byte HttpWebResponse are lower than the total objects I get via socket way. ...
4
10882
by: Hexman | last post by:
Code below ---- I've asked a similar question on this forum earlier. This is a slightly different situation. Previous Question ---- I'm trying to save some specific web pages to disk as text files. I searched the Internet and found a basic example which I changed to fit my needs. I tested it out first on a single URL and it worked fine. Now when I incorporate an array of URL's, it fails to work. The first "responseFromServer"...
0
1356
by: nukiee | last post by:
I wanted to check the status code that comes back as response from the HttpWebResponse. So I used the following code - res = (HttpWebResponse) req.GetResponse(); It's working great, but if I wanted to let the server know a date when I visited the server last using "IfModifiedSince" variable of the "req" object, the above piece of code throws an exception if the content was not modified since the time that I entered in the...
4
3081
by: Dean Rettig | last post by:
I am using HttpWebRequest to get an HttpWebResponse from an https:// site. I am using cookies and certificates and everything seems to be working properly EXCEPT... The largest (html) document that I am trying to read is about 28788 bytes when downloaded using Firefox but when my dotnet app tries to retrieve it, the response is only about
0
1122
by: jaydog0910 | last post by:
Hi all I have some something weird with the HttpWebResponse and I was hoping someone could help me understand what is going on. This problem is already fixed but for my own curiosity I was hoping someone would be able to shed some light. Here is a simplified version of the code: string sHtmlFile = "http://localhost/test.html"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sHtmlFile);
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.