using Rest client and getting statuscode 406 not acceptable

3.1k Views Asked by At

I'm using RestClient and redirecting the request to external REST webservice (java) as RestRequest. I'm getting HTTP statuscode 'not acceptable' and also the repsonse.content is something like this "The resource cannot be displayed because the file extension is not being accepted by your browser." the operation is successful but not able to get the required response which is nothing but a string value.

below is code snippet:

 var client = new RestClient();             
 client.BaseUrl = JavaWSURI;
 var request = new RestRequest();
 //request.AddHeader("Content-Length", int.MaxValue.ToString());
 //request.AddHeader("Content-Type", "text/html; charset=utf-8");
 // jsonD is JSON input object
 request.AddParameter("application/json", jsonD, ParameterType.RequestBody);
 request.Method = Method.POST;                
 request.RequestFormat = DataFormat.Json;

 // The server's Rest method will probably return something 
 var response = client.Execute(request) as RestResponse;
2

There are 2 best solutions below

0
On

From the error message, it sounds like you may need to add an 'Accept' header to the request

0
On

Add an Accept request header as follows:

request.AddHeader("Accept", 
              "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8");

Please note you may need to change the value depending on your content.