There is a Rest-service, written in Java. I enclose a code snippet. @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) I try to contact the address of the service from Android, everything works. But the type of response can not be established. If MediaType.APPLICATION_JSON goes first in the code above, then the response is received in JSON format, if I switch places, and MediaType.APPLICATION_XML goes first, then we get XML. The question is why the switch does not work in the Android client itself, by setting the request parameters conn.setRequestProperty("Content-Type", "application/xml"); ?
|
1 answer
Because when you do conn.setRequestProperty("Content-Type", "application/xml") , you say that you are sending a request of type application / xml.
To tell the service in which format you are waiting for a response, you need to pass the Accept header ( conn.setRequestProperty("Accept", "application/json") )
- Thank you very much. Every time after such questions, I am surprised at those who write documentation :) Why it’s impossible to write more clearly in the documentation :) - Evgeny Vartavanyan
- Please :) mark then my answer as correct - Sergi
|