How do I send JSon as BODY In a POST request to server from an Android application?

后端 未结 1 1916
别那么骄傲
别那么骄傲 2020-12-18 22:29

I am working on my first Android Application. What I am trying to do is a POST request to a REST service I want the BODY of this request to be a JSON String.

I am

相关标签:
1条回答
  • 2020-12-18 22:51

    Sorry folks, just turned out that the error was on the Rest service. I had change it and now it receives a String instead of the Reader object and it works as expected, the REST endpoint code on the server side now is:

    @POST
    @Path("/cadastrar/{userEmail}")
    @Consumes(MediaType.APPLICATION_JSON)
    public String cadastraPeso(@PathParam("userEmail") String email, String jsonString)
    {
            String json = jsonString;
            if(json != null)
            {
                log.debug("String json received from device ==>> " + json);
            }   
            return "OK - processed email ==>> " + email;
    }
    

    And the JSON string is correctly received on server side.

    So de Android code above is working as expected.

    0 讨论(0)
提交回复
热议问题