HttpWebRequest Err: An unexpected error occurred on a receive

G

Guest

Hai,

I'm trying to run an remote asp page which is on Windows 2003 server. After
running 2 Minutes i'm getting the following error (On Browser & Inside VB.NET
too).
The underlying connection was closed: An unexpected error occurred on a
receive.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at FetchHTMLContent(String RemoteURL, String& DownloadContent, Int32
TimeoutSeconds) in D:\Proj\VB.NET\clsUploadDownload.vb:line 20

VB.NET Code to run an asp page and return it's asp response.write's valu
--------------------------------------------------------------------------------------
Private Function FetchHTMLContent(ByVal RemoteURL As String, ByRef
DownloadContent As String, Optional ByVal TimeoutSeconds As Integer = 300) As
Boolean
Try
Dim objRequest As System.Net.HttpWebRequest
Dim objResponse As System.Net.WebResponse
Dim objStreamReceive As System.IO.Stream
Dim objStreamRead As System.IO.StreamReader

objRequest = CType(System.Net.WebRequest.Create(New
Uri(RemoteURL.ToString.Trim)), System.Net.HttpWebRequest)
'objRequest.KeepAlive = False
'objRequest.Proxy = System.Net.WebProxy.GetDefaultProxy()
'objRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
'objRequest.ProtocolVersion = System.Net.HttpVersion.Version10
'objRequest.Method = "GET"
'objRequest.ContentType = "application/x-www-form-urlencoded"
'objRequest.AllowAutoRedirect = True
'objRequest.MaximumAutomaticRedirections = 10
objRequest.Timeout = TimeoutSeconds * 1000 'Default 5 minutes
'objRequest.UserAgent = "Mozilla/3.0 (compatible; My Browser/1.0)"

objResponse = CType(objRequest.GetResponse(), System.Net.WebResponse)
objStreamReceive = objResponse.GetResponseStream
objStreamRead = New System.IO.StreamReader(objStreamReceive,
System.Text.Encoding.UTF8)
DownloadContent = objStreamRead.ReadToEnd()

FetchHTMLContent = True
Catch ex As Exception
Microsoft.VisualBasic.MsgBox(ex.Message.ToString &
Microsoft.VisualBasic.vbCrLf & ex.StackTrace)
End Try
End Function

So after googling found some tips to come accross this, but none of them
works for me
-----------------------------------------------------------------------------------------------------
1. KeepAlive set to false.
2. Set proxy objects & passed credentials
2. In IIS changed "Connection timeout" to 1800 seconds.
3. Changed responseDeadlockInterval as 00:30:00
httpRuntime executionTimeout = 1800
in file
%windir%\Microsoft.Net\Framework\<Framework_Version>\Config\Machine.config.

Any Ideas?

Bye
Ajai
 
S

sinc

Interestingly: when I use a proxy for this connection everything works
great. Of course, can't do this in production environment. Seems that
effects are cascading now--perhaps related to new MS auto updates?
 
J

Joerg Jooss

Ajai said:
Hai,

I'm trying to run an remote asp page which is on Windows 2003 server.
After running 2 Minutes i'm getting the following error (On Browser &
Inside VB.NET too).
The underlying connection was closed: An unexpected error occurred on
a receive.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
asyncResult) at System.Net.HttpWebRequest.GetResponse()
at FetchHTMLContent(String RemoteURL, String& DownloadContent,
Int32 TimeoutSeconds) in D:\Proj\VB.NET\clsUploadDownload.vb:line 20

VB.NET Code to run an asp page and return it's asp response.write's
value
----------------------------------------------------------------------
---------------- Private Function FetchHTMLContent(ByVal RemoteURL As
String, ByRef DownloadContent As String, Optional ByVal
TimeoutSeconds As Integer = 300) As Boolean Try
Dim objRequest As System.Net.HttpWebRequest
Dim objResponse As System.Net.WebResponse
Dim objStreamReceive As System.IO.Stream
Dim objStreamRead As System.IO.StreamReader

objRequest = CType(System.Net.WebRequest.Create(New
Uri(RemoteURL.ToString.Trim)), System.Net.HttpWebRequest)
'objRequest.KeepAlive = False
'objRequest.Proxy = System.Net.WebProxy.GetDefaultProxy()
'objRequest.Credentials =
System.Net.CredentialCache.DefaultCredentials
'objRequest.ProtocolVersion = System.Net.HttpVersion.Version10
'objRequest.Method = "GET" 'objRequest.ContentType =
"application/x-www-form-urlencoded"
'objRequest.AllowAutoRedirect = True
'objRequest.MaximumAutomaticRedirections = 10 objRequest.Timeout
= TimeoutSeconds * 1000 'Default 5 minutes
'objRequest.UserAgent = "Mozilla/3.0 (compatible; My Browser/1.0)"

objResponse = CType(objRequest.GetResponse(),
System.Net.WebResponse) objStreamReceive =
objResponse.GetResponseStream objStreamRead = New
System.IO.StreamReader(objStreamReceive, System.Text.Encoding.UTF8)
DownloadContent = objStreamRead.ReadToEnd()

FetchHTMLContent = True
Catch ex As Exception
Microsoft.VisualBasic.MsgBox(ex.Message.ToString &
Microsoft.VisualBasic.vbCrLf & ex.StackTrace)
End Try
End Function

So after googling found some tips to come accross this, but none of
them works for me.
----------------------------------------------------------------------
------------------------------- 1. KeepAlive set to false.
2. Set proxy objects & passed credentials
2. In IIS changed "Connection timeout" to 1800 seconds.
3. Changed responseDeadlockInterval as 00:30:00
httpRuntime executionTimeout = 1800
in file
%windir%\Microsoft.Net\Framework\<Framework_Version>\Config\Machine.co
nfig.

Try fixing your resource leak: You neither close your reader, nor your
stream, nor your response. Close at the least the reader within a
finally block.

Cheers,
 
R

redhotsly

Very interesting. We also started getting this error on 7/11/05. Did
you figure out the cause?

Thanks

Sylvain
 
R

Rick Sypriano

I also had the same problem and I was able to solve it by increasing the
"Connection Timeout" in IIS.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top