1
I need to send a JSON
generated in the application Android
for a web application.
Using the class HttpUrlConnection
I did the following encoding:
private void sendPost(String url, String postParams) {
try {
URL obj = new URL(url);
conn = (HttpURLConnection) obj.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Content-Length", Integer.toString(postParams.length()));
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(postParams);
wr.flush();
wr.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
When running, the system correctly sends the method URL and the JSON
, but the web application does not receive anything.
Using the plugin RESTClient
I did a test, put the same URL and the JSON
generated. When executing the method POST
the record was included correctly.
Why the application Android
is not sending the request correctly?
Look at this article, maybe I can help you: http://stackoverflow.com/questions/9767952/how-to-add-parameters-to-httpurlconnection-using-post
– Leonardo Rocha
is, I followed the indications of the commented post, but still is not executing the post method...
– Thiago