HttpClient in C# "application/vnd.pagerduty+json;version=2" format wrong


( #1

var client = new HttpClient(XXXX);

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/vnd.pagerduty+json;version=2”));

return error : format “application/vnd.pagerduty+json;version=2” wrong

anyone , has the similar experience?

(Demitri Morgan) #2

Hey Susan,

Just to share an idea I thought would be worth trying: consider how the MediaTypeWithQualityHeaderValue class seems to be designed for automatically formatting media types with quality precedence value (based on what I’m reading from the documentation on this class) per the format defined in RFC2616 §14.1. I think then that it might be worth trying the more generic class MediaTypeHeaderValue (see Documentation).

The format of the Accept header required by our REST API doesn’t specify multiple media types with their own quality values, but rather specifies one media type with a special version=n concatenated to the end of it to specify versioning. That might be why the MediaTypeWithQualityHeaderValue class isn’t accepting the format.

This is just conjecture, but might be that one of the = or ; characters are “confusing” it, because they would normally show up after a media type (in a value declaration), with a space in between the value and the media type.

(system) #3