How to add “Content-Type = application/json;v=2.0” including versioning with HttpClient?


April 2019


6 time


Sorry to ask this question like this. I can give you the feeling I would like you to do the code for me. I already spent a day tying to write the code to send a http request that contains a header with versioning:

For versioning I use the versioning by Media Type from Microsoft/aspnet-api-versioning project.

My API part is working fine and I can request the correct version without problem with Postman:

enter image description here

You see this line "Content-Type = application/json;v=2.0"? On postman no problem. With HttpClient from C# impossible to do.

Let me copy pas here all solution I tried with they error. I will Edit this question each time I try a new solution. By facility, but also to be more clear I will copy paste images:

Solution 1: The extension method with new Content

enter image description here

0 answers