0

我正在尝试在 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 url 来请求信息,但我没有能力安装正确的证书,所以证书也需要被忽略。

这是我到目前为止所尝试的:

<%@ 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>

我无法让负载忽略证书警告,并且在那一行出现解析错误。

4

1 回答 1

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>
于 2013-10-14T11:11:15.750 回答