c# - 为什么我必须设置 UseXmlSerializer = true 才能使用 XML 请求?
问题描述
使用 .NET Framework 4.7、C#、Postman。
我发出请求,请求标头 Content-Type 设置为“application/xml”。身体看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<BookOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<books>
<Book>
<bookName>Buzz</bookName>
<code>1234</code>
</Book>
</books>
</BookOrder>
我想,开箱即用,.NET Framework 4.7 接受 XML 请求并会以相同的方式响应,还是我弄错了?
相反,我必须在 Global.asax 中设置:
var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
xml.UseXmlSerializer = true;
为什么是这样?我试过不设置它,但无论我如何格式化它都不会接受我的 XML。请问有什么想法吗?
谢谢
我的课程是:
public class BookOrder
{
public List<Book> books{ get; set; }
}
public class Book
{
public string bookName { get; set; }
public string code { get; set; }
}
解决方案
推荐阅读
- python-3.x - 以半小时开始时间重新采样每日时间序列数据
- html - 2个带边框底线的span元素
- sdwebimage - 是否可以在 SDWebImage 缓存图像之前编辑图像的 url?
- javascript - AXIOS:我可以在 POST 请求中向 API 发送多个数据项吗?
- sql - 在 Oracle SQL 中格式化字符串
- c# - Rsa 加密解密中的错误长度错误
- node.js - 需要一些帮助 bodyparser
- python - 获取错误消息:切片列表时列表索引超出范围?
- java - 索引 0 超出 x.main 处长度 0 的范围
- python - 尝试在python django中用不同的键映射两个对应的值