0

我想从其他 asp.net 站点使用我博客的 RSS 提要。我无法获取 RSS 数据。我尝试了不同的方法(如 HttpWebRequest)来使用 RSS 提要,但我总是遇到同样的错误。

WebException was caught.
The underlying connection was closed: An unexpected error occurred during an import operation.

有什么问题?

提要地址:http ://blog.melihmucuk.com/feed/ 我需要帖子标题、链接和发布日期。

例如 :

Try

            Dim reader As XmlTextReader = New XmlTextReader("http://blog.melihmucuk.com/feed/")
            Dim ds As DataSet = New DataSet()
            ds.ReadXml(reader) // incorrect line

Catch ex As Exception

End Try

我认为,这是一个简单的任务,但我不知道是什么问题。

我也试试这个:

Try
            Dim title As String
            Dim link As String
            Dim description As String
            Dim reader = XmlReader.Create("http://blog.melihmucuk.com/feed/")//incorrect line

            Dim feed = SyndicationFeed.Load(reader)

            For Each item In feed.Items
                title = item.Title.Text
                link = item.Links(0).Uri.ToString
            Next

            HyperLink1.Text = title
            HyperLink1.NavigateUrl = link
            Label1.Text = description

        Catch ex As Exception

        End Try
4

1 回答 1

0

试试这个: -

Imports System.Web
Imports System.Net
Imports System.IO

Public Class Reader
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim rssFeed = New Uri("http://blog.melihmucuk.com/feed/")

            Dim request As WebRequest = WebRequest.Create(rssFeed)
            Dim response As WebResponse = request.GetResponse()

            Using reader As New StreamReader(response.GetResponseStream())
                Dim xdoc As XDocument = New XDocument()
                xdoc = XDocument.Load(reader)

                'Read the nodes and display as per your requirement.
            End Using

        Catch ex As Exception

        End Try
    End Sub

End Class

还要在您的 web.config 文件中添加此块:-

<configuration>
   <system.net>
    <defaultProxy useDefaultCredentials="true">
      <proxy usesystemdefault="true"/>
    </defaultProxy>
  </system.net>
</configuration>

在此处输入图像描述

于 2013-05-28T15:27:11.750 回答