E / Volley:[12083] BasicNetwork.performRequest:意外的响应代码404

时间:2019-02-05 09:45:29

标签: android rest web-services

我希望用户使用数据库凭据登录:

     final String link="http://166.62.29.42/sunrajadmin/login.php";
     final String string_username=editText.getText().toString(),string_password=editText1.getText().toString();
     if(string_username=="")
     {
         editText.setError("please enter username");
         editText.requestFocus();
     }
     else if(string_password=="")
     {
         editText1.setError("please enter password");
         editText1.requestFocus();
     }
     else
     {
         RequestQueue queue1= Volley.newRequestQueue(button.getContext());
         String url= Uri.parse(link).buildUpon()
                        .appendQueryParameter("username",string_username)
                        .appendQueryParameter("password",string_password).build().toString();
         StringRequest request1=new StringRequest( url, new Response.Listener<String>() {


             @Override
             public void onResponse(String response) {
                 Log.d("response",response);
                 if(response.contains("0 results"))
                 {
                     Toast.makeText(button.getContext(),"username/password are invalid",Toast.LENGTH_SHORT).show();
                 }
                 else {
                     try {
                         JSONObject object1 = new JSONObject(response);
                           String userid=object1.getString("id");
                           String name=object1.getString("name");
                           String email=object1.getString("email");
                           String mobile=object1.getString("mobile");
                           Session session=new Session(button.getContext());
                           session.userLoggedin(userid,name,email,mobile);
                           Intent i1=new Intent(button.getContext(),MainActivity.class);
                           startActivity(i1);
                           finish();

                     } catch (JSONException e) {
                         e.printStackTrace();
                     }
                 }
             }
                 },new Response.ErrorListener() {
             @Override
             public void onErrorResponse(VolleyError error) {
                 Toast.makeText(button.getContext(),"network error",Toast.LENGTH_SHORT).show();
                 error.printStackTrace();
                 }
         });
          queue1.add(request1);

     }

 }
});

1 个答案:

答案 0 :(得分:0)

404表示找不到页面,即找不到您所点击的URL。请确保您的URL正确并且您使用该服务的方法正确。