The underlying connection was closed

S

Suhail Kaleem

Hi !
When i try to use webrequest class i get this error

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

I ma uisng vb.net and have no control on the server Can any one tell me how
i do fix that form my code?



Thanks
Suhail Kaleem
 
H

Herfried K. Wagner [MVP]

Suhail Kaleem said:
When i try to use webrequest class i get this error

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

I ma uisng vb.net and have no control on the server Can any one tell me
how i do fix that form my code?

Does this only occur with a specific server only?
 
S

Suhail Kaleem

Hi !
I get this problem on localhost (IIS) and also on web with my
host !

Thanks
Suhail kaleem
 
S

Suhail Kaleem

Here is the code

Function get_web_data(ByVal url)


Dim html
' Debug.WriteLine(url)

'Create a WebRequest
Dim wrRequest As WebRequest
wrRequest = WebRequest.Create(url)

'Get the Response from the Request
Dim wrResponse As WebResponse = wrRequest.GetResponse()

'Read the Response into a stream and output the stream
Dim objStream As Stream = wrResponse.GetResponseStream()
Dim objStreamReader As StreamReader = New StreamReader(objStream)
Try
html += objStreamReader.ReadToEnd()
wrRequest.Abort()
objStream.Close()
objStreamReader.Close()

Catch ex As Exception
wrRequest.Abort()
objStream.Close()
objStreamReader.Close()
get_web_data = "Error: " & ex.Message.ToString
Exit Function
End Try

get_web_data = html
Debug.WriteLine(html)

End Function




Suhail Kaleem said:
Hi !
I get this problem on localhost (IIS) and also on web with my
host !

Thanks
Suhail kaleem
 

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