我已经实现了登录页面,我使用volley库在服务器端发送数据。所以请任何人告诉我如何将数据发送到服务器,其中数组和JSON中的登录请求如下所示。我知道这个问题已被某人提出,但我需要与Volley合作。
login request in array :- Array ( [User] => Array ( [username] => user [password] => India2016 ['service_auth']=>ture) )
login request in json:- {"User":{"username":"user","password":"India2016","service_aut"=>ture}}
以下是我的代码
private void LoginRequest() {
StringRequest stringRequest = new StringRequest(Request.Method.POST, LoginURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//showJSON(response);
Log.e("user_______",userId);
Log.e("pass_______",pass);
Log.e("response Login_________",response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(LoginActivity.this, " no internet connection", Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<String, String>();
map.put(KEY_EMAIL, userId);
map.put(KEY_PASSWORD, pass);
return map;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(LoginActivity.this);
requestQueue.add(stringRequest);