【发布时间】:2019-02-15 14:15:07
【问题描述】:
我在 phpmyadmin 上有以下 api。现在我想学习如何使用 volley lib 发送电子邮件和密码(字符串值)。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends MX_Controller {
public function index()
{
$json = file_get_contents('php://input');
$obj = json_decode($json, true);
$email = $obj['email'];
$password = $obj['password'];
if ($obj['email']!="") {
$this->load->module('camps');
$mysql_query = "SELECT * FROM accounts where email='$email' and password='$password'";
$result = $this->camps->_custom_query($mysql_query);
$query = $result->num_rows();
if ($query==0) {
echo json_encode($password);
}
else {
echo json_encode('OK');
}
}
else {
echo json_encode('Try Again');
}
}
}
}
我已经尝试过使用 getParams() 这样的方法,但它不起作用。
注意:uname 和密码是EditTexts
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("email",uname.getText().toString());
params.put("password",password.getText().toString());
return params;
}
【问题讨论】:
-
您应该使用 JsonObjectRequest 并发送带有电子邮件和密码字段的 JsonObject。注意,密码真的不应该是纯文本
-
@cricket_007 你能告诉我如何发送带有这些字段的 JsonObject。
-
您在创建
new JSONObject()时遇到问题吗?它的文档相当简单 developer.android.com/training/volley/request -
查看示例 stackoverflow.com/a/26033484/2308683 或使用 Gson 作为有用的库 developer.android.com/training/volley/request-custom
标签: android api android-volley