in Education by
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 using google's GSON to generate the JSON that is sent to the server. Here is the code doing POST request: HttpPost requisicao = new HttpPost(); requisicao.setURI(new URI(uri)); requisicao.setHeader("User-Agent", sUserAgent); requisicao.setHeader("Content-type", "application/json"); HttpResponse resposta = null; //I can see the json correctly print on log with the following entry. Log.d(TAG, "JSon String to send as body in this request ==>> " + jsonString); //than I try to send JSon using setEntityMethod StringEntity sEntity = new StringEntity(jsonString, "UTF-8"); requisicao.setEntity(sEntity); resposta = httpClient.execute(requisicao); resultado = HttpProxy.leRespostaServidor(resposta); The response code is 400 BAD REQUEST and from the server log I can read the info. where it says the body was not correctly sent: 13:48:22,524 ERROR [SynchronousDispatcher] Failed executing POST /peso/cadastrar/[email protected] org.jboss.resteasy.spi.BadRequestException: Could not find message body reader for type: class java.io.Reader of content type: application/json The code for the server side is a simple Seam Rest Service: @POST @Path("/cadastrar/{userEmail}") @Consumes(MediaType.APPLICATION_JSON) public String cadastraPeso(@PathParam("userEmail") String email, Reader jsonString) { LineNumberReader lnr = new LineNumberReader(jsonString); try { String json = lnr.readLine(); if(json != null) { log.debug("String json recebida do device ==>> " + json); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "OK - o e-mail processado foi ==>> " + email; } What could be wrong with the Android client code? I have researched the web and did not find any really useful information about this error. []s JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
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.

Related questions

0 votes
    I want to send the following JSON text {"Email":"[email protected]","Password":"123456"} to a web ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I want to send files asynchronously. I got on sending a file client->server->another client, but if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I want to send files asynchronously. I got on sending a file client->server->another client, but if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do here is get the headers of a given URL so I can determine the MIME type. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Which of the following code retrieves the body of the request as binary data? (a) DataInputStream data = new ... & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
0 votes
    I am a very novice C# person so please dont be too hard on me Im trying to make a post request ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How can we POST JSON data with cURL?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I am trying to scrape the data off the webpage below, using Selenium in Python 3: https://www. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I am trying to scrape the data off the webpage below, using Selenium in Python 3: https://www. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    This is a cURL function that can send or retrieve data. It should work with any PHP app that ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    first of all,i am fairly new with spring mvc so .. how springmvc find the right class to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have the following HTML/ASP.NET code: Ny test Name: When using the "POST" form post method I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I am working in an graphql application where I have to send custom error object / message in json ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...