I am trying the AsyncHttpClient
library for Android and am trying to make a HTTP POST with it to my Express (NodeJS) server and I am having difficulties attaching parameters to the POST request.
This is what I do:
AsyncHttpClient httpClient = new AsyncHttpClient();
RequestParams requestParams = new RequestParams();
requestParams.put("username", usernameEditText.getText().toString());
requestParams.put("password", passwordEditText.getText().toString());
httpClient.post("http://1.2.3.4/sign-up", requestParams, new JsonHttpResponseHandler() {
// here I override the onSuccess and onFailure methods
}
But when the request comes to the Express server, I can't find the parameters anywhere. I was used to finding the POST parameters in req.body
, but:
app.post('/sign-up', function(req, res) {
var username = req.body.username; // throws error because req.body is undefined
});
Is the AsyncHttpClient
library broken or am I doing something wrong on either side?
You're probably missing the body-parser middleware.