Error 406 Not Acceptable JSON Error 406 Not Acceptable JSON json json

Error 406 Not Acceptable JSON


A 406 HTTP status means that if a web server detects that the data it wants to return is not acceptable to the client, it returns a header containing the 406 error code.The client can define the characteristics of the data it will accept back from the web server by using the accept headers.
In this case you declare the you would like to accept application/json:

Request.AddHeader("Accept", "application/json");

however the REST API method you are invoking is returning text/plain.
You should change the code to accept text/plain:

Request.AddHeader("Accept", "text/plain");


Wanted to add this for for future users stuck like me. I was having the same issue and tried the request with Postman and saw that the Content-Type was "application/hal+json" I was trying it with application/json without luck.

So running a test in postman I was able to figure out what the server needed exactly.

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/hal+json"));


I faced the same 406 Error: Not Acceptable when trying to get JSON on another site. In my case I could see correct JSON when typed url in my browser address field. But downloading it from the same url via my C# code have been producing 406 Error.None of the answers in this topic solved my problem directly. But at least they pointed out to me that's the point is HTTP headers.

So I googled that page:https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sendingand added all browser headers to my code, and voila! It started to work.In my case it was enough to fill some data in user-agent header.