Problem with Posting JSON object with WSRequest
I want Play to call a webservice. The webservice accepts application/json
and returns this as well. With the following code I'm trying to achieve this. (Note, the headers.put(xxx)
are added later in an effort to solve the problem).
WSRequest request = WS.url(targetURL);
request.body = new Gson().toJson(user);
request.headers.put("Content-type","application/json");
request.headers.put("Accept","application/json");
request.post();
The strange thing is that my JBOSS server replies: "Cannot consume content type". If I use my 'Simple REST client' plugin in my Chrome browser, and provide the entire JSON Body GSon created and add the cont开发者_如何学运维ent-type header, I get a valid response. Is this not the way to send JSON to the server? Or am I missing some fundamental piece here?
While checking the API documentation on the WSRequest class i noticed the field mime-type By setting it as follows JBOSS (resteasy) accepted my request succesfully.
request.mimeType = "application/json";
精彩评论