我实际上正在制作一个登录应用程序,但无法登录。这是我的mainactivity.java我怎么可能做错了?
ppublic class MainActivity extends AppCompatActivity {
private EditText email, password;
private Button btn_login;
private ProgressBar loading;
private static String URL_LOGIN ="http://itsolutionsnepal.com/attendance/api/employeeLogin";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loading= findViewById(R.id.loading);
email = findViewById(R.id.editTextUserEmail);
password = findViewById(R.id.editTextPassword);
btn_login = findViewById(R.id.buttonRegister);
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String mEmail = email.getText().toString().trim();
String mPassword = password.getText().toString().trim();
if (!mEmail.isEmpty() || !mPassword.isEmpty()) {
Login(mEmail, mPassword);
}else{
email.setError("Please Enter Email");
password.setError("Please Enter Password");
}
}
});
}
private void Login(final String email, final String password) {
loading.setVisibility(View.VISIBLE);
btn_login.setVisibility(View.GONE);
StringRequest stringRequest = new StringRequest(Request.Method.POST,URL_LOGIN,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray jsonArray = new JSONArray(response);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
String name = object.getString("_first_name").trim();
String email = object.getString("_email").trim();
// JSONObject jsnobject = new JSONObject(response);
// JSONArray jsonArray = jsnobject.getJSONArray("");
//JSONObject object = jsonArray.getJSONObject(i);
// JSONObject jsonResponse = new JSONObject(response);
//
// JSONArray jsonArray = jsonResponse.getJSONArray("");
//JSONObject jsonObject = new JSONObject(response);
// Log.d("JSON", jsonObject.toString());
//String success = jsonObject.getString("");
// JSONArray jsonArray = jsonObject.getJSONArray("");
// JSONArray jsonArray = new JSONArray(response);
// JSONObject jsonObject = new JSONObject("");
// String code = jsonObject.getString("");
// if (success.equals("1"))
// {
// String name =
object.getString("_first_name").trim();
// String email =
object.getString("_email").trim();
// Toast.makeText(MainActivity.this,
"Success
Login \nYour name: "+name+"\nYour Email: "+email,
// Toast.LENGTH_LONG).show();
System.out.println("Value of response - " +
response);
System.out.println("First Name : " + name);
System.out.println("Email : " + email);
Intent intent = new Intent(MainActivity.this, HomeActivity.class);
intent.putExtra("name",name);
intent.putExtra("email", email);
startActivity(intent);
loading.setVisibility(View.GONE);
//}
}
} catch (JSONException e) {
e.printStackTrace();
loading.setVisibility(View.GONE);
btn_login.setVisibility(View.VISIBLE);
Toast.makeText(MainActivity.this, "Error" +e.toString(),
Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "Error" +error.toString(),
Toast.LENGTH_LONG).show();
loading.setVisibility(View.GONE);
btn_login.setVisibility(View.VISIBLE);
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("_email", email);
params.put("_password", password);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
这是我的php代码:
这是我的错误日志:
我正在为我的大学项目开发此软件。我的代码有什么问题?
编辑:这是邮递员的全屏截图
答案 0 :(得分:2)
截击请求中的键与您的POSTMAN屏幕截图矛盾。您在密码和电子邮件之前添加了下划线,因为您从PHP代码Login credential wrong please try again!
中获得了字符串响应。我建议您将状态代码添加到响应中,然后根据错误进行解析
@Override
protected Map<String, String> getParams(){
Map<String, String> params = new HashMap<>();
params.put("email", email);
params.put("password", password);
return params;
}
使用MD5也不是secure