我的目标是从API中提取XML数据并将其加载到SQL服务器数据库中。我正在尝试的第一步是访问数据并显示它。一旦我成功,我将循环遍历每一行并将值插入到SQL服务器数据库中。当我尝试运行下面的代码时,什么也不会发生,当我直接将URL粘贴到浏览器中时,会出现以下错误:
"2010-03-08 04:24:17 Wallet exhausted: retry after 2010-03-08 05:23:58. 2010-03-08 05:23:58"
在我的看法中,foreach循环的每一次迭代都会对该网站进行调用,导致我被封禁了一个小时。我是以错误的方式从API检索数据吗?是否有一种方法可以将数据加载到内存或数组中,然后遍历它?
这是我拼凑出来的代码片段。
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
string userID = "123";
string apiKey = "abc456";
string characterID = "789";
string url = "http://api.eve-online.com/char/WalletTransactions.xml.aspx?userID=" + userID + "&apiKey=" + apiKey + "&characterID=" + characterID;
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(url);
XmlNamespaceManager xnm1 = new XmlNamespaceManager(xmldoc.NameTable);
XmlNodeList nList1 = xmldoc.SelectNodes("result/rowset/row", xnm1);
foreach (XmlNode xNode in nList1)
{
Response.Write(xNode.InnerXml + "<br />");
}
}
catch (SqlException em)
{
Response.Write(em.Message);
}
}
}
这是一个 XML 的示例。
<eveapi version="2">
<currentTime>2010-03-06 17:38:35</currentTime>
<result>
<rowset name="transactions" key="transactionID" columns="transactionDateTime,transactionID,quantity,typeName,typeID,price,clientID,clientName,stationID,stationName,transactionType,transactionFor">
<row transactionDateTime="2010-03-06 17:16:00" transactionID="1343566007" quantity="1" typeName="Co-Processor II" typeID="3888" price="1122999.00" clientID="1404318579" clientName="unseenstrike" stationID="60011572" stationName="Osmeden IX - Moon 6 - University of Caille School" transactionType="sell" transactionFor="personal" />
<row transactionDateTime="2010-03-06 17:15:00" transactionID="1343565894" quantity="1" typeName="Co-Processor II" typeID="3888" price="1150000.00" clientID="1404318579" clientName="unseenstrike" stationID="60011572" stationName="Osmeden IX - Moon 6 - University of Caille School" transactionType="sell" transactionFor="personal" />
</rowset>
</result>
<cachedUntil>2010-03-06 17:53:35</cachedUntil>
</eveapi>