【发布时间】:2021-03-01 12:32:37
【问题描述】:
旧系统会向我发送此信息:
POST /xml HTTP/1.1
Host: localhost:9000
User-Agent: curl/7.64.1
Accept: */*
Content-Length: 321
Content-Type: multipart/mixed; boundary=------------------------a9dd0ab37a224967
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part1"
Content-Type: text/xml
<foo>bar</foo>
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part2"
Content-Type: application/json
{'foo': 'bar'}
--------------------------a9dd0ab37a224967--
我需要解释为原始XElement 的第一部分;对于第二部分,我想要通常的模型绑定。
我试试这个:
class Part2 {
public string foo { get; set; }
}
[HttpPost]
[Route("/xml")]
public string Post1([FromBody] XElement part1, [FromBody] Part2 part2 )
{
return part1.ToString() + ", " + part2.foo;
}
但是 ASP.NET 不允许使用多个[FromBody] 修饰的参数。
如何让我的 ASP.NET Core 服务接收内容类型为 multipart/mixed 的 http 请求?
【问题讨论】:
-
这是我之前关于解释原始 xml here 的问题的后续。
标签: http asp.net-core multipart