php - How get data in Symfony2 from android's post method -
i have android app makes post function sending data symfony project. want these data , storage in bd. think problem in php code , not in android's. have tried in lot of ways 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 new user:
new_user: pattern: /new_user defaults: { _controller:tortillatorapitortillatorbundle:default:newuser}
and symfony function in 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; }
just errors saw, big comment:
change part:
and symfony function in 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; }
into this, if using annotations, otherwise have specify routing , method differently, aswell i've changed request object.:
/** *@route("yourroute", name="yourroute") *@method("post") *@template() */ public function newuseraction(request $request) { $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; }
Comments
Post a Comment