private void postRequest() {
// Request a string response from the provided URL.
// Instantiate the RequestQueue.
String url = "http://10.0.0.9:3000/hello";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try{
Log.i("*********", "******");
response.put("Hello", "World");
}catch(JSONException e){
Log.i("JSONERROR", e.toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO: Handle error
Log.i("*********", error.toString());
}
});
jsonObjectRequest.setRetryPolicy(new RetryPolicy() {
@Override
public int getCurrentTimeout() {
return 1000;
}
@Override
public int getCurrentRetryCount() {
return 1000;
}
@Override
public void retry(VolleyError error) throws VolleyError {
}
});
This is the Android code
app.post('/hello', function(req,res){
console.log(JSON.stringify(req.body))
})
This is the node js code
So the problem im having is that im printing the body to the console but it keeps showing up empty. As you can see in the postRequest method ive put 'hello as key' and 'world as value' in the jsonobject. So it is calling the correct post request, the body is just empty and cant figure out why that is.
Edit----- Ive checked the content with wireshark and content length is 0 so im not sending anything it seems. if im understanding this correctly