1

I have an Accept header like this:

application/myapp+json;version=2.0

however when I try and use it the constructor for System.Net.Http.Headers.MediaTypeWithQualityHeaderValue rejects it as invalid. Nancy doesn't seem to mind it.

It seems it doesn't like the semi colon. What is the 'right way' to specify a specific version is desired in the header and what are the rules I should follow to generate 'valid' Accept headers?

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • You could try adding the header without validation. Also why not just use a `MediaTypeHeaderValue` – Nkosi Nov 22 '17 at 19:02
  • yeah we can work around it, but I want to know what the rules are. – Sam Holder Nov 22 '17 at 19:05
  • Tested with something like `var added = client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/myapp+json;version=2.0");` and worked fine. The media type was parsed and the version was added as a parameter of the header. As for the rules that is way too broad to answer here. – Nkosi Nov 22 '17 at 19:13
  • `MediaTypeHeaderValue` has the same issue, and yes we can add without validation, and maybe the *full* rules is too much for here (but link maybe...), but what is wrong with the header we are using? There should be something obvious should there not? – Sam Holder Nov 22 '17 at 19:24
  • I see nothing wrong with your media type at a glance based on my experience with using them – Nkosi Nov 22 '17 at 19:25

0 Answers0