gpt4 book ai didi

c# - 使用 ASP.Net 获取和显示 RSS 提要

转载 作者:行者123 更新时间:2023-11-30 17:24:13 24 4
gpt4 key购买 nike

我需要阅读并在我的网页中显示此提要。

http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public

使用 c# net 2。

我试过这个教程:

http://www.aspsnippets.com/Articles/Fetch-and-Display-RSS-Feeds-using-ASP.Net.aspx

但错误是:

A column named 'link' already belongs to this DataTable: 
cannot set a nested table name to the same name.

为什么?

下面是我的代码。

如果您能在解决这个问题时给我任何帮助,我将不胜感激。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="FeedPicasa_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rssRepeater" runat="server">
<ItemTemplate>
<table style="border: solid 1px black; width: 500px; font-family: Arial">
<tr>
<td style="font-weight: bold">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("link")%>' Text='<%#Eval("title")%>'></asp:HyperLink>
</td>
</tr>
<tr>
<td>
<hr />
</td>
</tr>
<tr>
<td style="background-color: #C2D69B">
<asp:Label ID="Label1" runat="server" Text='<%#Eval("description")%>'></asp:Label>
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>


using System;
using System.Net;
using System.Xml;
using System.Data;

public partial class FeedPicasa_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetRSS();
}

private void GetRSS()
{
//Create a WebRequest
WebRequest rssReq =
WebRequest.Create("http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public");

//Create a Proxy
WebProxy px = new WebProxy("http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public", true);

//Assign the proxy to the WebRequest
rssReq.Proxy = px;

//Set the timeout in Seconds for the WebRequest
rssReq.Timeout = 5000;
try
{
//Get the WebResponse
WebResponse rep = rssReq.GetResponse();

//Read the Response in a XMLTextReader
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());

//Create a new DataSet
DataSet ds = new DataSet();

//Read the Response into the DataSet
ds.ReadXml(xtr);

//Bind the Results to the Repeater
rssRepeater.DataSource = ds.Tables[2];
rssRepeater.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
}

最佳答案

如何使用如下所示的纯 Javascript/jQuery 解决方案:

Javascript

$(function(){
url = 'http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public';
$.ajax({
type: "GET",
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
error: function(){
alert('Unable to load feed, Incorrect path or invalid feed');
},
success: function(xml){
values = xml.responseData.feed.entries;

$.each(values, function( index, value ) {
$('#myFeed').append(value.content);
$('#myFeed').append('<br/>');
});
}
});
});

HTML

<div id="myFeed"/>

工作 fiddle

http://jsfiddle.net/5EtnX/1/

描述

上面的代码只是对提要进行了 json 调用,在成功函数内它循环结果并使用 jQuery 附加输出提要的内容。

关于c# - 使用 ASP.Net 获取和显示 RSS 提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com