Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 17th, 2006, 07:13 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default Error with Webrequest

Hi

In short, I am trying to receive response using webrequest and webresponse, but I am getting the error:

The underlying connection was closed: An unexpected error occurred on a receive.

Have googled a lot, have set the proxy, keepAlive property etc (all that I could), but no avail. While googling I found that a lot of people have this problem, but no resolution. Hope anyone can help.

Regards
Mike
__________________
Regards
Mike
  #2 (permalink)  
Old October 17th, 2006, 07:25 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Mike,
   Depending on what you are doing with your request, you may or may not need to provide proxy credentials. (Though it may also depend on your firewall setup)

For example, when pulling RSS feeds into my agency I have to provide proxy credintials to access the website and pull back the feed but, when I work with a remote API such as UPS I do not need to provide my credentials.

This is more or less what my code looks like

System.Net.WebProxy oProxy = new System.Net.WebProxy("proxy", port);
System.Net.HttpWebRequest httpWebRequest = System.Net.HttpWebRequest.Create("url");
oProxy.Credentials = new System.Net.NetworkCredential("user", "password");
httpWebRequest.Method = "POST";
httpWebRequest.Proxy = oProxy;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Accept = "text/xml";
StreamWriter streamWriter = new System.IO.StreamWriter(httpWebRequest.GetRequestSt ream());
streamWriter.Write((strXMLAccess + strXMLRate));
System.Net.HttpWebResponse httpWebResponse = httpWebRequest.GetResponse();
StreamReader streamReader = new System.IO.StreamReader(httpWebResponse.GetResponse Stream());

Also the owner of the resource you are connecting to has the ability to set their own timeout (for example, UPS's API times out after 120s) so if your process is hanging at the resource it may be that the resource itself is forcing the connection to close. Unfortunately there is no real cure all for this if you have verified that your code works (e.g. connected it to another resource and were able to pull back data successfully) contact the owner of the resource you are having trouble with and see if they can advise.

hth

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #3 (permalink)  
Old October 17th, 2006, 07:33 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Douglas

Don't know how, but magically I am able to pass the network problem pasting your code, but now the request is taking a lot of time and it times out (while fetching the reponse).

By the way for testing purpose I am trying to fetch response from
http://www.microsoft.com/windows/default.mspx

Any ideas!!

Regards
Mike
  #4 (permalink)  
Old October 17th, 2006, 07:52 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What kind or response are you fetching? Are you writing anything to the site and expecting a return based on what you write to the Request stream?

My code above write data to the request stream (it is how I work with a remote API and I recieve different responses form the API depending on what i write to the request stream)

This is code I use to just grab a response (I use it to get RSS feeds and thus, don't need to write anything to the request stream)

System.Net.HttpWebRequest httpWebRequest = System.Net.HttpWebRequest.Create(strXMLURL);
System.Net.WebProxy oProxy = new System.Net.WebProxy("proxy", port);
oProxy.Credentials = new System.Net.NetworkCredential("user", "password");
httpWebRequest.Method = "GET";
httpWebRequest.Proxy = oProxy;
httpWebRequest.Accept = "text/xml";
System.Net.HttpWebResponse httpWebResponse = httpWebRequest.GetResponse();
object streamReader = new System.IO.StreamReader(httpWebResponse.GetResponse Stream());
object stringResult = streamReader.ReadToEnd();
StringReader sr = new StringReader(stringResult);
XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc.Load(sr);
System.Net.HttpWebResponse httpWebResponse = httpWebRequest.GetResponse();
StreamReader streamReader = new System.IO.StreamReader(httpWebResponse.GetResponse Stream());

hth


-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #5 (permalink)  
Old October 17th, 2006, 07:58 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Parsons

There seems to be a bit confusion. Simply help me with this, I WANT TO READ THE HTML CONTENTS OF THE PAGE "http://www.microsoft.com/windows/default.mspx" AND DISPLAY IT

That's it, hope u can help me out

Regards
Mike
  #6 (permalink)  
Old October 17th, 2006, 08:01 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Oh, your trying to do a screen scrape! This article should explain it.

http://www.4guysfromrolla.com/webtech/070601-1.shtml <<--Basic
http://aspnet.4guysfromrolla.com/articles/102605-1.aspx <<--Advanced

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WebRequest Response Error hpatel_it ASP.NET 2.0 Basics 0 October 17th, 2006 06:50 AM
Experts?? Problem w/ Webrequest MAtkins ASP.NET 1.0 and 1.1 Professional 2 April 9th, 2006 10:21 PM
WebRequest Authentication venterjo ASP.NET 1.0 and 1.1 Professional 0 November 2nd, 2005 08:07 AM
WebRequest on local machine burdickdave C# 0 November 5th, 2003 07:36 PM



All times are GMT -4. The time now is 08:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.