C# 系统集成测试 - 获取执行时返回的结果
<!DOCTYPE html PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> 测试系统集成 </title>
</head>
<body>
<br>
<script type="text/javascript" src="js/integration.js"></script>
<form method="post" action="/api/DeviceInterface/IntegrationServlet" style="margin-top:8px;margin-bottom:5px" onsubmit="return commit()">
<table style="margin-left: 0px;margin-bottom:5px;margin-top:0px" width="99%">
<tr>
<td width="50%" style="border-style:solid;border-width:1px;border-color:#91D4FF;">
<table align="left" width="50%" align="center" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td align="left" class="even" nowrap><b>State(Y-Success,N-Wrong): </b>N</td>
</tr>
<tr>
<td align="left" class="even" nowrap><b>Return info: </b><SFDM_ERROR><MESSAGE >用户名或密码错误!</MESSAGE></SFDM_ERROR></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<script type="text/javascript">
//window.onload=function(){try{parent.complete();}catch(e){}};
</script>
<p>如何提取执行时返回的结果</p>
<p>用C#写一个例程内容:可以使用C#中的HttpWebRequest和HttpWebResponse类来发送POST请求,并从响应中获取返回结果。</p>
<p>以下是示例代码:</p>
<pre><code class="language-csharp">using System;
using System.IO;
using System.Net;
using System.Text;
class Program
{
static void Main(string[] args)
{
string url = "http://yourapiurl.com/api/DeviceInterface/IntegrationServlet";
string postData = ""; //这里填写POST请求的数据
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] data = Encoding.UTF8.GetBytes(postData);
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string result = "";
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
}
//这里的result就是执行时返回的结果,可以根据需要进行处理
Console.WriteLine(result);
}
}
</code></pre>
<p>在上面的示例代码中,需要替换url和postData变量的值为实际的请求地址和数据。可以根据实际情况修改Content-Type头和编码方式。</p>
<p>获取到返回结果后,可以根据需要进行解析和处理,例如使用XML解析器来解析返回的XML数据。</p>
原文地址: https://www.cveoy.top/t/topic/n1Wl 著作权归作者所有。请勿转载和采集!