The obvious reason for this would be not providing proper content type. But I am providing. Still i am getting Unsupported Media Type. Not sure why. Any help greatly appreciated.
Client c = Client.create(); WebResource resource = c.resource(HOST+"/test"); Gson gson = new Gson(); Test test = new Test(); test.setTestName("TEST AUTOMATION"); resource.header("Content-Type", "Application/json"); String testStr = gson.toJson(test); System.out.println("Request Str: "+testStr); ClientResponse response = resource.post(ClientResponse.class, testStr); System.out.println("POST response : "+response); POST response : POST http://host:8888/test returned a response status of 415 Unsupported `enter code here`Media TypeAnswer1:
This is how i solved it. Its really weird. Until i combine the statements as below, it didn't work. From the above program that i wrote, combine the header statement and post statement as below. Also don't forget to put charset=UTF-8.
ClientResponse response = resource.header("Content-Type", "application/json;charset=UTF-8").post(ClientResponse.class, testStr);