0
我有一個android應用程序,它使post函數將數據發送到Symfony項目。然後我想在bd中獲得這些數據和存儲。我認爲問題出在我的php代碼中,而不是在android中。我嘗試了很多方法,但沒有結果。如何從android的post方法中獲取Symfony2中的數據
我的Android的職位功能:
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();
}
新用戶的路由:
new_user:
pattern: /new_user
defaults: { _controller:TortillatorAPITortillatorBundle:Default:newUser}
在我控制我的Symfony的功能:
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;
}
會發生什麼事?任何錯誤? – Xatenev
儘管getRequest已被棄用。 – Xatenev
當我執行我的android功能時,它不收回迴應,所以它不會發生任何事情 – xaaleja