473,403 Members | 2,183 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,403 software developers and data experts.

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 1347
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Angel | last post by:
I'm trying to connect to a fixed IP address (eg. http://10.60.903.50/TempFile) in order to retrieve one accii line of text in TempFile. I try to read the information with this code: string...
26
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On...
3
by: MattM | last post by:
I am getting the "The underlying connection was closed: Unable to connect to the remote server" message when trying to connect an ASPX page to a simple Hello World web service. I have read a few...
5
by: Vijayakrishna Pondala | last post by:
Hi, We are using the following error randomly, when accessing a webservice method/servlet hosted on JBoss application server: The underlying connection was closed: An unexpected error occurred...
4
by: Matthew.DelVecchio | last post by:
hello, i am developing an ASP.NET web app that consumes a 3rd party vendor webservice. it is my first one so while ive done my homework, im not an expert on the matter. our partner's...
1
by: Tim Reynolds | last post by:
Team, From a windows service, we consume a web service on another server and occasionally receive System.Net.WebException: The underlying connection was closed:. For some clients we call, we do...
3
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously...
2
by: =?Utf-8?B?RnJpZWRoZWxtRWljaGlu?= | last post by:
I am consuming continously my own web-services on a localhost client with a rate of perhaps 35 request/response-pairs a minute. I am using "invoke-id=1", so there is at the same time only one...
4
by: =?Utf-8?B?QXJuYXVkIFZpc2N1c2k=?= | last post by:
Hi all, we meet a problem since we use WCF to consume java WebServices. Often the first call works then the second raises the following error : "The underlying connection was closed : " We...
4
by: Sin Jeong-hun | last post by:
I don't get the message so it's hard to debug that, but some of my clients report that they get "The underlying connection was closed unexpectedly" exception. According to this site (http://...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.