Search code examples
c#web-api-contrib

Usage content-type with webapicontrib.formatting.xlsx


I'm using webapi2 and webapicontrib.formatting.xlsx to create Excel files.

If i add this line in the webapiconfig.cs it works ok

    config.Formatters.Clear();

But then I loose the possibility of default content negotiation, i mean, if request something as json or from the browser (expecting xml) it always retrieves the binary, so I removed that line (I prefer the default behaviour)

I tried adding in the request:

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

But doesn't retrieve the file, it uses the json formatter.

How can I maintain the default formatters behaviour (having added the xlsx one in webapiconfig.cs) and and when request a specific url get the file?

Thanks. Guillermo.


Solution

  • Instead of Content-Type the correct one is Accept, like

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