【发布时间】:2020-06-03 06:33:31
【问题描述】:
我有以下 XML 输入。我需要调用 API 并将其作为输入传递,但值会动态变化。如何构建这个输入结构?
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="http://tempuri.org/">
<acc>test</acc>
<pass>abc</pass>
<xmlInvData>
<![CDATA[
<MyData>
<name>test</name>
<number>900</number>
</MyData>
]]>
</xmlInvData>
<username>test</username>
<password>123</password>
</Test>
</soap:Body>
</soap:Envelope>
我在 C# 中有 MyData 类,可用于设置 name 和 number 值。
但是我怎样才能形成一个完整的结构并传递给 Api 调用呢?肥皂:信封和肥皂体?
HttpClient httpClient = new HttpClient();
string requestUri = "https://testurl";
var byteArray = Encoding.ASCII.GetBytes("username:password");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
HttpResponseMessage response = await httpClient.PostAsync(requestUri, httpContent);
我需要了解如何在我的输入 json 上形成 httpContent。
【问题讨论】:
标签: c# .net c#-4.0 dotnet-httpclient