 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 17th, 2006, 07:13 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

October 17th, 2006, 07:25 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

October 17th, 2006, 07:33 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

October 17th, 2006, 07:52 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

October 17th, 2006, 07:58 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|
 |