如何在 Android 中使用 Volley 和 Java 而不使用 PHP 来检索 MySql 数据?
最佳答案
要与服务器通信,您必须用 java 编写 API。其中将包括数据库名称、用户名、访问密码、获取数据的sql查询。
StringRequest stringRequest = new StringRequest(Request.Method.POST, DB_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// responce may be String, JSONOnject, JSONArray. Handle with your own actions.
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Error occurs in API(loop,TimeOutError,...)
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
// Map your Key and Value to match in the API to perform actions.
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest);
关于android - 如何在没有php的情况下在android中使用java使用volley检索mysql数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39341546/