使用 webapicontrib.formatting.xlsx 的内容类型

Usage content-type with webapicontrib.formatting.xlsx

我正在使用 webapi2 和 webapicontrib.formatting.xlsx 创建 Excel 个文件。

如果我在 webapiconfig.cs 中添加这一行,它就可以正常工作

    config.Formatters.Clear();

但后来我放弃了默认内容协商的可能性,我的意思是,如果请求 json 或从浏览器(期望 xml)它总是检索二进制文件,所以我删除了那个行(我更喜欢默认行为)

我尝试在请求中添加:

    Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

但不检索文件,它使用 json 格式化程序。

如何维护默认的格式化程序行为(在 webapiconfig.cs 中添加了 xlsx)以及何时请求特定的 url 获取文件?

谢谢。吉列尔莫.

正确的是接受而不是内容类型,比如

    Accept: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet