Thanks for the great article Jeff Lewis
Helped me get something running in my app. I have one issue I wonder if you could explain?
The URL my app is calling is expected a POST request with the Content-Type “application/x-www-form-urlencoded”, as opposed to your application/json example.
I am using your approach for a HashMap and JSON object to set my parameters pulled from UI elements like so…
Here is the sample of my JSONTask class to extend AsyncTask…
When I check the output logs from my Node App running the service I see the request body appears like this…
{"{\"email\":\"jsmith@liveperson.com\",\"sub\":\"g3\",\"fname\":\"John\",\"exp\":\"10\",\"lname\":\"Smith\"}"
}Consequently the body parameters I am looking for are not found due to the encoding/format of the POST made from Android and the service fails…
However when I make a call from POSTMAN the logs show the request body as expected like so…
{"sub":"auth-user-id-2","exp":"5"}I presume the issue is with this section where the JSON object is used by the OutPutStreamWriter ?
if (this.postData != null) {
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(postData.toString());
writer.flush();
}Appreciate any suggestions you could give? Android is still very new for me coming from a javascript background.
Thanks again,
John
