我想如果客户端在调用 Web api 时没有提供内容类型,在服务器端将其设置为 application/json,我发现了这个:
SetConfig(new HostConfig {
PreferredContentTypes = new []{ MimeTypes.Json }.ToList(),
});
在 this关联 但当我编写此代码时,编译器无法识别 Setconfig。
- 我将 servicestack 设置为 Web api 中的默认序列化程序
编辑:
我关注了this用于替换 servicestack.text 而不是 Web api 的默认序列化器的指令。 我不知道应该把这个配置放在哪里,因为当我把它放在 ServiceStackTextFormatter 构造函数中时,编译器无法识别 SetConfig。
最佳答案
使用Config.DefaultContentType
例如:
SetConfig(new HostConfig {
DefaultContentType = MimeTypes.Json
});
关于c# - 如何使用 servicestack 序列化程序将默认内容类型设置为 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48850232/