0
明显的原因是没有提供正确的内容类型。但我提供。仍然我得到不受支持的媒体类型。不知道为什么。任何帮助不胜感激。Jersey客户端导致415不支持的媒体类型
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 Type
服务器能处理json内容吗? – 2014-09-29 16:04:04
您已经告诉了请求什么是内容类型,但是您的服务器上的方法是否说明它支持哪种类型?他们必须匹配。我期望服务器端方法有一个像@ @Consumes(MediaType.APPLICATION_JSON)''的注释。 – TedTrippin 2014-09-29 16:18:20
我的服务器可以处理json内容。 – 2014-09-30 04:43:04