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

WebResponse.GetResponse Error

Calling the System.Net.WebResponse.GetResponse method (see
code below) results in the following error:

System.Net.WebException: The underlying connection was
closed: An unexpected error occurred on a receive.
at(System.Net.HttpWebRequest.CheckFinalStatus())
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult
asyncResult)
at(System.Net.HttpWebRequest.GetResponse())

The URL works ok in IE on the same PC.

Does anyone know what would cause this problem, what other
checks I could try or any other method to do the same
thing as System.Net.WebResponse.GetResponse?

Thank you in advance.

Private Function HasWebConnection() As Boolean
Dim bResult As Boolean
Try
bResult = True
Dim URI As New System.Uri("http://www.microsoft.com")
Dim TestRequest As Net.WebRequest =
Net.WebRequest.Create(URI)
TestRequest.Timeout = Threading.Timeout.Infinite
Dim TestResponse As Net.WebResponse =
TestRequest.GetResponse
Catch ex As Exception
Console.WriteLine(ex.ToString)
bResult = False
End Try
Return bResult
End Function

Jul 21 '05 #1
6 6109
Hi,

Thanks for your post. I tested your code, and it works properly on my side.
Now I'd like to share the following information with you:

1. Since IE works properly, I'd like you to check connection setting in IE
options, especially, the proxy setting. You can use WebProxy to set HTTP
proxy for the WebRequest class.

WebProxy Class
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemnetwebproxyclasstopic.asp

2. I recommend you use the sample in KB article 303436 and check whether or
not it works on your side.
SAMPLE: Visual C# .NET Networking Classes HTTP Internet Client
http://support.microsoft.com/?id=303436

I look forward to your result.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #2
Hi,

Thank you for your informative reply.

When I checked the proxy settings in IE I found that under
the dial-up connection settings the proxy was disabled but
under LAN Settings that the proxy was incorrectly enabled.
Since I am using a dial-up connection I did not think that
this would make any difference (It even states "These
settings will not apply to any dial-up or VPN
connections.") but as a test, I disabled them anyway and
much to my surprise the code worked. I also tried
disconnecting the network cable but it made no difference.
The code always attempted to use the proxy settings under
LAN Settings regardless of the fact that the connection to
the Internet was via a dial-up connection.

This raises another question. Many of my application users
will have laptops that they will connect to a LAN when
they are in the office and to the Internet via dial-up
connections at home. I was hoping just to use the settings
in IE and not have the user set up special settings in my
application. Is there a way of checking which are the
appropriate proxy settings to use.

Thank you,

Jonathan
-----Original Message-----
Hi,

Thanks for your post. I tested your code, and it works properly on my side.Now I'd like to share the following information with you:

1. Since IE works properly, I'd like you to check connection setting in IEoptions, especially, the proxy setting. You can use WebProxy to set HTTPproxy for the WebRequest class.

WebProxy Class
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/cpref/html/frlrfsystemnetwebproxyclasstopic.asp

2. I recommend you use the sample in KB article 303436 and check whether ornot it works on your side.
SAMPLE: Visual C# .NET Networking Classes HTTP Internet Clienthttp://support.microsoft.com/?id=303436

I look forward to your result.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Jul 21 '05 #3
Hi,

Sorry for the double post. I forgot provide my alias.

Thank you for your informative reply.

When I checked the proxy settings in IE I found that under
the dial-up connection settings the proxy was disabled but
under LAN Settings that the proxy was incorrectly enabled.
Since I am using a dial-up connection I did not think that
this would make any difference (It even states "These
settings will not apply to any dial-up or VPN
connections.") but as a test I disabled them anyway and
much to my surprise the code worked. I also tried
disconnecting the network cable but it made no difference.
The code always attempted to use the proxy settings under
LAN Settings regardless of the fact that the connection to
the Internet was via a dial-up connection.

This raises another question. Many of my application users
will have laptops that they will connect to a LAN when
they are in the office and to the Internet via dial-up
connections at home. I was hoping just to use the settings
in IE and not have the user set up special settings in my
application. Is there a way of checking which are the
appropriate proxy settings to use.

Thank you,

Jonathan
-----Original Message-----
Hi,

Thanks for your post. I tested your code, and it works properly on my side.Now I'd like to share the following information with you:

1. Since IE works properly, I'd like you to check connection setting in IEoptions, especially, the proxy setting. You can use WebProxy to set HTTPproxy for the WebRequest class.

WebProxy Class
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/cpref/html/frlrfsystemnetwebproxyclasstopic.asp

2. I recommend you use the sample in KB article 303436 and check whether ornot it works on your side.
SAMPLE: Visual C# .NET Networking Classes HTTP Internet Clienthttp://support.microsoft.com/?id=303436

I look forward to your result.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Jul 21 '05 #4
Hi Jonathan,

Thanks for your update. Generally speaking, the WebRequest will get the
proxy information from the settings in IE. If it is using DUN, you can add
the following code to clear the proxy:

Dim myProxy = New Net.WebProxy
TestRequest.Proxy = myProxy

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #5
Hi,

Isn't this a bug in WebRequest? It is not getting using
the proxy settings of the active connection from IE. It
uses the settings under LAN even when there is no LAN
connection.

I see that the code that you sent would clear the proxy
but how would I detect that the user is has a DUN
connection and then how do I know if they don't have proxy
settings on the DUN.

Thanks,

Jonathan
-----Original Message-----
Hi Jonathan,

Thanks for your update. Generally speaking, the WebRequest will get theproxy information from the settings in IE. If it is using DUN, you can addthe following code to clear the proxy:

Dim myProxy = New Net.WebProxy
TestRequest.Proxy = myProxy

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Jul 21 '05 #6
Hi Jonathan,

Thanks for your feedback.
Isn't this a bug in WebRequest? Based on my experience, WebRequest only gets the proxy information from IE
settings and does not check what the active connection is.
I see that the code that you sent would clear the proxy but how would I

detect that the user is has a DUN connection and then how do I know if they
don't have proxy settings on the DUN.

Though you can call GetAdaptersInfo() from you .NET managed application via
P/Invoke to check whether the computer connects via LAN or DUN, I strongly
recommend you catch the exception and try using WebRequest without proxy to
work around this problem.

I look forward to your feedback.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #7

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

Similar topics

0
by: amine | last post by:
I really need help on this please. I am writing an application for an Ipaq and I am trying to enable the application to connect to a DAV server which can is basically an HTTP server that acts like...
1
by: Jacob | last post by:
Please help figure what I am doing wrong in this code. All I am trying to do is send come data to an aspx page and get some data back. I watched my variable in debug mode and can tell that I am...
0
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the...
2
by: gizmo | last post by:
Hi, I'm using the following code to request the html source from the quoted site. ...... string url = "http://www1.soccerstand.com/"; WebRequest webRequest = WebRequest.Create(url);...
6
by: Jonathan | last post by:
Calling the System.Net.WebResponse.GetResponse method (see code below) results in the following error: System.Net.WebException: The underlying connection was closed: An unexpected error occurred...
4
by: Savas Ates | last post by:
I have a vb.net web application. I want to post some variables to another web page and take some values back and process them. This is codes in my target url. I should post "langpair" cariable...
3
by: KyleUbenk | last post by:
Well I have a multi-threaded program which downloads URL sources from the web. Im doing this multiple times at once. The only problem I see is that sometimes it takes a while to download the...
4
by: CindyH | last post by:
Hi I'm trying to use webrequest - webresponse to post a stream. I have set up a simple test with one aspx form holding the post code and trying to get another aspx form to receive the post on...
0
by: deeps1512 | last post by:
hi All, I have written the following code to get a webresponse. XmlDocument myxmlDoc1 = new XmlDocument(); myxmlDoc1.LoadXml(BkXMLRQ); string s = myxmlDoc1.OuterXml;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.