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