I have an android app which makes a post function sending data to a Symfony project. Then I want to get these data and storage in my bd. I think the problem is in my php code and not in android's. I have tried in a lot of ways but with no result.
My android's post function:
public String sendPost(String username, String password, String email, String city) {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost("https://192.168.1.120/TortillatorAPI/web/new_user");
HttpResponse response = null;
try
{
List<NameValuePair> params = new ArrayList<NameValuePair>(4);
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("city", city));
httpPost.setEntity(new UrlEncodedFormEntity(params));
response = httpClient.execute(httpPost, localContext);
}
catch (Exception e)
{
}
return response.toString();
}
The routing for a new user:
new_user:
pattern: /new_user
defaults: { _controller:TortillatorAPITortillatorBundle:Default:newUser}
And my Symfony function in my controller:
public function newUserAction()
{
$request = $this->getRequest();
$user = new User();
$user->setUsername($request->get('username'));
$user->setPassword($request->get('password'));
$user->setEmail($request->get('email'));
$user->setCity($request->get('city'));
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
$response = new Response();
$response->setStatusCode(201);
return $response;
}