【发布时间】:2019-03-15 19:09:19
【问题描述】:
我正在为我的 WebApi 创建一个新路由,它应该通过 HTTP POST 接收以下 XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AcquireKeysRequest>
<version>2</version>
<content>
<id>MTV</id>
<type>VOD</type>
</content>
<protection>
<protection-system>
<type>DASH-CENC</type>
<system-id>urn:mpeg:dash:mp4protection:2011</system-id>
</protection-system>
</protection>
<key-timing>
<position>0</position>
</key-timing>
</AcquireKeysRequest>
我已经通过框架映射它,使用以下模型:
public class AcquireKeysRequest
{
public int Version { get; set; }
public Content Content { get; set; }
public Protection Protection { get; set; }
public KeyTiming KeyTiming { get; set; }
}
public class Content
{
public string Id { get; set; }
public string Type { get; set; }
}
public class Protection
{
public ProtecionSystem ProtectionSystem{ get; set; }
}
public class ProtecionSystem
{
public string Type { get; set; }
public string SystemId { get; set; }
}
public class KeyTiming
{
public int Position { get; set; }
}
当我收到没有标头的请求时
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
映射工作得很好,但是当我添加标题时,它会中断。 我怎样才能忽略它?
[HttpPost]
[Route("{instanceId}")]
public object AcquireKeyRequest([FromUri]int instanceId, AcquireKeysRequest xml)
{
//SomeLogicHere
}
P.S:我知道模型和 XML 中的名称是不同的,我已经在我的代码中修复了。
【问题讨论】:
标签: c# xml asp.net-web-api xml-serialization