c# - c# RestClient 在发送以 XML 作为参数的 Post 请求时出错
问题描述
我正在尝试使用 RestClient 将 HttpResults 更新为 ALM Octane,结果是 XML 不遵守 XSD。
当我使用邮递员时,它运行良好。但是 C# 代码失败了。
XML - >
<test_result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<release_ref id="123" />
<product_areas>
<product_area_ref id="233" />
</product_areas>
<test_fields>
<test_field type="Framework" value="TestNG" />
<test_field type="Testing_Tool_Type" value="Selenium" />
<test_field type="Test_Level" value="System Test" />
<test_field type="Test_Type" value="Regression" />
</test_fields>
<environment>
<taxonomy type="AUT Env" value="Production" />
</environment>
<test_runs>
<test_run class="Login" duration="741" package="TestProject" status="Passed" name="Validate Login Page" />
</test_runs>
</test_result>
API 链接 -> API 链接
我目前正在使用的代码。
StreamReader reader = new StreamReader(path);
string ret = reader.ReadToEnd();
reader.Close();
String URI = "/api/shared_spaces/" + sspace + "/workspaces/" + wspace + "/test-results";
var client = new RestClient(octaneBaseUrl);
client.Authenticator = new HttpBasicAuthenticator(userId, pwd);
var request = new RestRequest(URI, Method.POST);
request.AddHeader("Content-Type", "application/xml");
request.AddParameter("xmlBody", ret);
IRestResponse response = client.Post(request);
string res = response.Content;
在发送 POST 之前,我应该在 XML 中包含 XML 标记吗?
解决方案
推荐阅读
- sql-server - Microsoft.EntityFrameworkCore.Database.Command[20102] - 字节 [] 数据有问题
- python - Python 中关于“删除”的概念
- javascript - (JS)使用嵌套对象数组的路径转换对象数组
- mysql - 在 SQL SELECT 语句中使用变量及其评估
- javascript - Java Script:如何将条件存储在字符串中并将其传递到 IF 条件块中?
- python - PyQt5登录注册对话框自动关闭
- python - Python + pyenv + librosa + Big Sur 的问题
- typescript - 如何在 Vue3 SFC 中导入打字稿文件并使用 laravel mix 构建它
- flutter - 从本地设备 Flutter 加载视频
- python - Python在Django应用程序中抛出变量范围错误