我正在尝试将用户电子邮件地址和密码从我的 android 应用程序发送到数据库以通过 POST 登录。
在服务器端,我得到这样的数据:
$email = $_POST['email'];
$password = clean($_POST['password'];
在 android 端我发送它是这样的:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("some real URL");
httppost.setHeader("Content-type", "application/json");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(params));
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httppost);
......
即使我输入有效的登录详细信息,它也会失败并显示没有电子邮件地址或密码。我发送的东西正确吗?
我也尝试过像下面这样发送数据,但没有用。有什么建议么?
JSONObject obj = new JSONObject();
obj.put("email", email );
obj.put("password", password);
httppost.setEntity(new StringEntity(obj.toString()));