我试图从服务器(Laravel)获取令牌并保存到数据库(android),但是当向服务器发送请求时,我得到这个错误:
E/Volley: [276] BasicNetwork.performRequest: Unexpected response code 401 for http://192.168.1.4:8000/api/user/login
E/Volley: [276] BasicNetwork.performRequest: Unexpected response code 401 for http://192.168.1.4:8000/api/user/login
D/error: com.android.volley.AuthFailureError
安卓代码 (java) :
public void loginUser(String email, String password, final OnLoginResponse onLoginResponse){
JSONObject requestJsonObject=new JSONObject();
try {
requestJsonObject.put("email",email);
requestJsonObject.put("password",password);
JsonObjectRequest request=new JsonObjectRequest(Request.Method.POST, "http://192.168.1.4:8000/api/user/login",requestJsonObject , new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
onLoginResponse.onResponse(response.optString("token"));
Log.d("response",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("error",error.toString());
}
}) {
我使用邮递员检查了客户端,这不是问题,返回令牌没有问题。
这是邮递员的截图:
慕妹3146593
相关分类