我正在尝试在IIS7服务器上的网页中显示版本信息。我真的不知道我在做什么,但我希望这是处理服务器端,我假设这意味着使用asp的一些变体。我知道如何使用php做类似的事情,但这不是这个项目的选项。 xml文档来自同一服务器上的本地资源,使用以下URL:
https://127.0.0.1:8443/webservice/rm-agent/v1/monitor/devices?scope%3Dequipment
并且in chrome的输出如下所示:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<DEVICES count="3" time="13-10-12 16:29:20">
<VIEW name="all" scope="equipment">
<DEVICE mac_address="88:E0:F3:20:08:B9" model="WLC2" system_ip="192.168.1.99/24" sw_version="8.0.3.6.0" location="""" name="WLC2" license="WLAN Access Points:4Adv Voice:1Mesh/Bridging:4High-Availability:1Spectrum Analysis:4" object-id="com.trapeze.appl.shared.mdl.Chassis: 28660" contact="" serial_number="KE3211500127"/>
<DEVICE mac_address="f8:c0:01:ab:54:c0" model="WLA532-US" system_ip="192.168.1.75" name="name-WLA1" object-id="com.trapeze.appl.shared.mdl.DistributedAP: 29143" serial_number="jb0212039600">
<RADIOS_INFO radio_1_type="802.11ng" radio_2_mac_address="f8:c0:01:ab:54:c1" radio_2_type="802.11na" radio_1_mac_address="f8:c0:01:ab:54:c0"/>
</DEVICE>
<DEVICE mac_address="ac:4b:c8:02:68:00" model="WLA532-US" system_ip="192.168.1.82" name="WLA9999" object-id="com.trapeze.appl.shared.mdl.DistributedAP: 167425" serial_number="jb0212294341">
<RADIOS_INFO radio_1_type="802.11ng" radio_2_mac_address="ac:4b:c8:02:68:01" radio_2_type="802.11na" radio_1_mac_address="ac:4b:c8:02:68:00"/>
</DEVICE>
</VIEW>
</DEVICES>
我真的只需要一个显示第一个响应元素的sw_version的html页面,所以它基本上只是一个页面说:
8.0.3.6.0
另一个问题是我被迫使用https网址来请求信息,但我没有能力安装合适的证书,因此也需要忽略证书。
这是我到目前为止所尝试的:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ ServicePointManager.ServerCertificateValidationCallback = delegate( object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors ) { return true; }; %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string url = @"https://127.0.0.1:8443/webservice/rm-agent/v1/monitor/devices?scope%3Dequipment";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(url);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<pre>
<asp:Literal ID="lit1" runat="server" />
</pre>
</div>
</form>
</body>
</html>
我无法让负载忽略证书警告,并且在该行上出现解析错误。
答案 0 :(得分:1)
感谢@John Saunders获取忽略证书警告请求的帮助。 我无法解析XML,我认为因为它源于一种奇怪的格式,或者更可能是因为我不知道我在做什么,但我得到它的工作,所以这就是我所关心的: d 这是我最终使用的代码:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate( object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors ) { return true; };
string url = "https://127.0.0.1:8443/webservice/rm-agent/v1/monitor/devices?scope%3Dequipment";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(url);
string xmlString = xmlDoc.OuterXml;
string testString = Regex.Match(xmlString, @"sw_version=""([^)]*)"" location").Groups[1].Value;
Response.Write("<center><h2>The Current Version Is:</h2><h1>"+testString+"</h1></center>");
}
</script>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Version</title>
</head>
<body>
</body>
</html>