473,387 Members | 1,464 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,387 software developers and data experts.

HttpWebResponse.GetResponse() hangs my program.

Hi Friends,

I have this code in a C# console application which calls a URL on my
website(Asp.net/C#) with Querystrings. (I have also tried without
querystrings).

The problem is my program gets hanged. Even no error message is
displayed.

HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(CaptureURLForSch eduler +
strQueryString);
req.Method = "POST";

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(strQueryString);
req.ContentLength = byte1.Length;

//This line hangs my program
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//This line hangs my program

Can you tell me what's going on and how can i fix this?

Regards,
Mahernoz

Oct 17 '07 #1
4 3338
Is the URL well-formed? Have you tried pasting the eventual URL Into your
browser's address bar and requesting the "page"?
You could try the simplified WebClient class with
string s= WebClient.DownloadString(url)

and see if you still have a problem.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Mahernoz" wrote:
Hi Friends,

I have this code in a C# console application which calls a URL on my
website(Asp.net/C#) with Querystrings. (I have also tried without
querystrings).

The problem is my program gets hanged. Even no error message is
displayed.

HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(CaptureURLForSch eduler +
strQueryString);
req.Method = "POST";

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(strQueryString);
req.ContentLength = byte1.Length;

//This line hangs my program
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//This line hangs my program

Can you tell me what's going on and how can i fix this?

Regards,
Mahernoz

Oct 17 '07 #2
On Oct 17, 4:16 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yohohhoandabottleofrum.comwrote :
Is the URL well-formed? Have you tried pasting the eventual URL Into your
browser's address bar and requesting the "page"?
You could try the simplified WebClient class with
string s= WebClient.DownloadString(url)

and see if you still have a problem.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Mahernoz" wrote:
Hi Friends,
I have this code in a C# console application which calls a URL on my
website(Asp.net/C#) with Querystrings. (I have also tried without
querystrings).
The problem is my program gets hanged. Even no error message is
displayed.
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(CaptureURLForSch eduler +
strQueryString);
req.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(strQueryString);
req.ContentLength = byte1.Length;
//This line hangs my program
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//This line hangs my program
Can you tell me what's going on and how can i fix this?
Regards,
Mahernoz
Hi,

yes, the url is welformed.

i do get a response when i tried pasting the eventual URL Into my
browser's address bar. But the GetResponse method is taking
lots of time (it doesn't seem to complete, i guess an infinite loop,
deadlock ,etc).

Regards,
Mahernoz.
Oct 17 '07 #3
"Mahernoz" <ma******@gmail.comwrote in message
news:11*********************@k35g2000prh.googlegro ups.com...
Hi Friends,

I have this code in a C# console application which calls a URL on my
website(Asp.net/C#) with Querystrings. (I have also tried without
querystrings).

The problem is my program gets hanged. Even no error message is
displayed.

HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(CaptureURLForSch eduler +
strQueryString);
req.Method = "POST";

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(strQueryString);
req.ContentLength = byte1.Length;

//This line hangs my program
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//This line hangs my program

Can you tell me what's going on and how can i fix this?
I think you're a little confused about the difference between the GET method
and the POST method and what content is. The strQueryString isn't content.
It forms part of the URL (that is the ID of the resource you are
requesting). If you really wanted to send content using a POST you should
be retrieving the RequestStream from the WebRequest and saving data to the
stream.

Ditch the content length and change POST to GET.

Does it work now?

--
Anthony Jones - MVP ASP/ASP.NET
Oct 17 '07 #4
Mahernoz wrote:
yes, the url is welformed.

i do get a response when i tried pasting the eventual URL Into my
browser's address bar. But the GetResponse method is taking
lots of time (it doesn't seem to complete, i guess an infinite loop,
deadlock ,etc).
When you load it in the browser, does it actually complete loading?
What is the page you're hitting on the server? A ASP/PHP/CGI script?

I've seen instances where a lot of data being pushed to the client from
a web-based script without any kind of buffering will exhibit this kind
of behaviour. It effectively keeps streaming the data to the client
until it's loaded, and if there's several hundred records it could take
the script a while to do that, depending on how complex they are,
language used, server hardware, etc...

In reality the problem clears itself up if you let it go because it's
not really "hung" in the sense of crashed, but it's just waiting for the
webserver to finish serving it the page before returning your value.

Chris.
Oct 17 '07 #5

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

Similar topics

0
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...
0
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...
5
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...
13
by: Jason Manfield | last post by:
For some URLs (e.g.http://v3.espacenet.com/origdoc?DB=EPODOC&IDX=WO2005028634&F=0&QPN=WO2005028634), the content length for the HttpWebResponse I get with request.GetResponse in empty. The...
4
by: Nuno Magalhaes | last post by:
In a simple thread I have a code like the one below: public void ProtectionRun() { while(true) { //Sleep thread for one minute //Thread.Sleep(60000); HttpWebRequest...
3
by: Nuno Magalhaes | last post by:
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(60000); HttpWebRequest
2
by: STEVE.KING | last post by:
Greetings: I need to download an executable and some other binary files (a C++ DLL) from a virtual directory in my WinForms application. No-Touch Deployment manages my .NET code fine but...
4
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...
1
by: Shayz | last post by:
Hi, I have been working on this code now, well about 5 lines, for 3 days now and I am completely baffled. I have an ASP.NET page whch takes in variables and using them variables pings them to a...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.