首先,我还是一个编码初学者(尤其是C#和dotnet环境)。我正在尝试创建一个包含从 XML 文件获取的数据的表。为了从 XML 文件访问数据,需要凭据。访问 XML 的代码在代码文件中完成。问题是,当我运行代码时正在显示 XML 文件,但是当我选择一个元素(例如“标题”)时,我想将数据显示到表格中
protected void Page_Load(object sender, EventArgs e)
{
String sUsername = "administrator";
String sPassword = "123";
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(sUsername + ":" + sPassword));
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("//pageurl");
httpWebRequest.Headers.Add("Authorization", "Basic " + encoded);
httpWebRequest.PreAuthenticate = true;
HttpWebResponse webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (webResponse.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = webResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.Default);
string pageContent = streamReader.ReadToEnd();
Debug.Print("Web response output as follows:");
TextArea1.Text = pageContent;
}
}
上面是代码,下面是前端
<form id="form1" runat="server">
<div>
<asp:TextBox id="TextArea1" TextMode="multiline" Columns="50" Rows="5" runat="server" />
</div>
</form>
有什么办法可以调用一些xml数据并将其显示在表格中吗?
相关分类