Is there a reason why URIs are considered invalid when used as media type parameters?
We can set an Accept header of this form, as long as we bypass validation:
The following code throws a FormatException:
At the moment I'm struggling to see how to achieve this.
We can set an Accept header of this form, as long as we bypass validation:
var msg = new HttpRequestMessage();
msg.Headers.TryAddWithoutValidation(
"Accept",
"application/hal+json; profile=http://example.org/profile/1");
However, when treated as a collection such a header appears to be empty. I suspect this is related to the validation code around the NameValueHeaderValue class, as attempting to use this to subsequently add the parameter values also fails.The following code throws a FormatException:
msg.Headers.Accept.ParseAdd(
"application/hal+json; profile=http://example.org/profile/1");
A little more background on what I'm trying to do, in case that's any help: I'm hoping to use content negotiation to select a media type from the Accept header and then parse its parameters to determine how to format the output.At the moment I'm struggling to see how to achieve this.