[英]How to submit invalid XML through QTP Web Services
我正在尝试使用QTP中的Web服务工具提交XML。 我可以毫无问题地提交有效的XML,但是当我尝试提交无效的XML进行负面测试时(例如,当元素值应为有效日期时将其设置为“ XXX”)。 我一直在线出错
设置SubmitXMLRequest = WebServices(webservicename).submitRequest(subReq)
该错误显示“ XML文档中存在错误(92,8),来自以下错误:mscorlib字符串未被识别为有效的日期时间
如何防止在提交请求之前验证XML的数据?
您是否尝试过通过QTP而不使用Web服务工具来访问Web服务? 我通过QTP / UFT运行我们所有的Web服务,而没有套件的那一部分,我可以将所需的任何内容提交给我们的API。
提交格式错误的XML / JSON数据后,我必须检查响应,以确保检查在主服务处理之前已经完成,这听起来像您正在尝试做的事情。
没有实际使用该工具,它可以在提交请求之前验证您的请求吗? 如果是这种情况,则可能无法注入错误的请求数据。
我相信您正在使用UFT API模块。 UFT解析XML,因此您将无法在数据部分输入XML特殊字符&和<。 您可以使用以下功能来执行xml请求发布。 这就是我现在在项目中使用的。
public static string HttpRequest(string url, string xml)
{
string response = string.Empty;
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebResponse = null;
httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Timeout = 10000;
try
{
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(xml);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.ContentType = "text/xml; encoding='utf-8'";
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode == HttpStatusCode.OK)
{
using (Stream responseStream = httpWebResponse.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream))
response = reader.ReadToEnd();
}
}
httpWebResponse.Close();
}
catch (Exception ex)
{
throw new Exception ("Error");
}
finally
{
if (httpWebResponse != null)
{
httpWebResponse.Close();
httpWebResponse = null;
}
httpWebRequest = null;
}
return response;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.