469,622 Members | 1,462 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,622 developers. It's quick & easy.

Underlying connection was closed (with sample code)

LS
Hello,
I'm building an rss reader, works fine for all rss feeds, except for this
one (you can try the sample code)
The program stops on myxml.LoadXml(content)

Any ideas why this happens, I'm searching already for 2 days now.

code
-------------------------------------------------------------------------
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net
Imports System.IO
Module Module1

Sub Main()
Dim req As HttpWebRequest
Dim res As HttpWebResponse
Dim myreader As StreamReader
Dim content As String
req = HttpWebRequest.Create("http://www.politics.be/backend2.php")
req.UserAgent = "Mozilla/6.0 (MSIE 6.1; Windows NT 5.1;)"
req.MaximumAutomaticRedirections = 20
req.Timeout = 10000
req.Proxy = GlobalProxySelection.GetEmptyWebProxy()
req.KeepAlive = False
res = req.GetResponse
myreader = New StreamReader(res.GetResponseStream)
content = myreader.ReadToEnd()
myreader.Close()
myreader = Nothing
res.Close()
res = Nothing
req = Nothing
Dim myxml As New Xml.XmlDocument
Console.WriteLine(content)
myxml.LoadXml(content) 'this line gives the problem
myxml = Nothing
Console.ReadLine()
End Sub

End Module
-------------------------------------------------------------------------------------
Nov 21 '05 #1
3 1204
Hi,

You dont need the webrequest and webresponse. Here is a simple
example.
Private Const filename As String = "http://www.politics.be/backend2.php"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim reader As XmlTextReader = Nothing

Try
' Load the reader with the data file and ignore all white space
nodes.
reader = New XmlTextReader(filename)
reader.WhitespaceHandling = WhitespaceHandling.None
Dim bWrite As Boolean = False
' Parse the file and display each of the nodes.
While reader.Read()
Select Case reader.NodeType
Case XmlNodeType.Element
If reader.Name = "title" Then bWrite = True
'Trace.WriteLine(String.Format("<{0}>",
reader.Name))
Case XmlNodeType.Text
If bWrite Then Trace.WriteLine(reader.Value)
Case XmlNodeType.CDATA
' Trace.WriteLine(String.Format("<![CDATA[{0}]]>",
reader.Value))
Case XmlNodeType.ProcessingInstruction
'Trace.WriteLine(String.Format("<?{0} {1}?>",
reader.Name, reader.Value))
Case XmlNodeType.Comment
'Trace.WriteLine(String.Format("<!--{0}-->",
reader.Value))
Case XmlNodeType.XmlDeclaration
'Trace.WriteLine("<?xml version='1.0'?>")
Case XmlNodeType.Document
Case XmlNodeType.DocumentType
'Trace.WriteLine(String.Format("<!DOCTYPE {0}
[{1}]", reader.Name, reader.Value))
Case XmlNodeType.EntityReference
'Trace.WriteLine(reader.Name)
Case XmlNodeType.EndElement
bWrite = False
'Trace.WriteLine(String.Format("</{0}>",
reader.Name))
End Select
End While

Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
Ken
-----------------------
"LS" <in*****@invalid.com> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello,
I'm building an rss reader, works fine for all rss feeds, except for this
one (you can try the sample code)
The program stops on myxml.LoadXml(content)

Any ideas why this happens, I'm searching already for 2 days now.

code
-------------------------------------------------------------------------
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net
Imports System.IO
Module Module1

Sub Main()
Dim req As HttpWebRequest
Dim res As HttpWebResponse
Dim myreader As StreamReader
Dim content As String
req = HttpWebRequest.Create("http://www.politics.be/backend2.php")
req.UserAgent = "Mozilla/6.0 (MSIE 6.1; Windows NT 5.1;)"
req.MaximumAutomaticRedirections = 20
req.Timeout = 10000
req.Proxy = GlobalProxySelection.GetEmptyWebProxy()
req.KeepAlive = False
res = req.GetResponse
myreader = New StreamReader(res.GetResponseStream)
content = myreader.ReadToEnd()
myreader.Close()
myreader = Nothing
res.Close()
res = Nothing
req = Nothing
Dim myxml As New Xml.XmlDocument
Console.WriteLine(content)
myxml.LoadXml(content) 'this line gives the problem
myxml = Nothing
Console.ReadLine()
End Sub

End Module
-------------------------------------------------------------------------------------

Nov 21 '05 #2
LS
> You dont need the webrequest and webresponse. Here is a simple
example.


I know that this is possible, but why is the example not working, it works
for all other rss feeds.
I need the webrequest because I need info from the HEAD of the webserver.
(the code is just an example to show what is not working.
Nov 21 '05 #3
LS
> I'm building an rss reader, works fine for all rss feeds, except for this
one (you can try the sample code)
The program stops on myxml.LoadXml(content)

Is anybody able to reproduce this problem?
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

26 posts views Thread by Rajeev Tipnis | last post: by
3 posts views Thread by MattM | last post: by
2 posts views Thread by =?Utf-8?B?RnJpZWRoZWxtRWljaGlu?= | last post: by
4 posts views Thread by =?Utf-8?B?QXJuYXVkIFZpc2N1c2k=?= | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.