Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

New Post: URIs in media type parameters

$
0
0
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:
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.

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>