Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 406 Not Acceptable JSON

http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-CreateorReplaceRepositoryConfiguration

I am using the Create or Replace Repository Configuration call. However I am getting a 406 Error: Not Acceptable. Other PUT calls are working but do not return JSON. I believe JSON is the source of the error but have not been able to resolve or prove this.

I have added the code as below

RestClient Client = new RestClient(uriString);
RestRequest Request = new RestRequest(requestType);

Request.AddHeader("Authorization", "Basic " + credentials);
Request.AddHeader("Accept", "application/json");

I've seen threads where adding the header to accept JSON resolves the error but this has not worked for me.

like image 383
user3464189 Avatar asked Jan 13 '15 20:01

user3464189


People also ask

What does 406 not acceptable mean?

The HyperText Transfer Protocol (HTTP) 406 Not Acceptable client error response code indicates that the server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiation headers, and that the server is unwilling to supply a default representation.


1 Answers

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");
like image 87
Dror Bereznitsky Avatar answered Oct 19 '22 02:10

Dror Bereznitsky