3

我有一个使用 Volley 请求的应用程序。当 SIM 1 是我首选的数据 SIM 卡时,它运行良好。在双卡上切换首选数据卡时,我收到了一个volley 404 error请求。

我的 Volley 方法看起来像这样(与一张 SIM 卡完美配合):

 private void login() {
        loading = ProgressDialog.show(context, null, "Authenticating.Please wait...",true,true);
        StringRequest strReq = new StringRequest(Request.Method.POST,
                MyApplication.Online_Login, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.e(TAG, "response: " + response);

                try {
                    JSONObject obj = new JSONObject(response);

                    // check for error flag
                    if (obj.getString("error").equals("false")) {
                        // user successfully logged in
                        loading.dismiss();
                        JSONObject userObj = obj.getJSONObject("user");
                        String id=userObj.getString("requestor_id");
                        String nam= userObj.getString("name");
                        String ema=userObj.getString("email");
                        User user = new User(id,nam,ema);
                        // storing user in shared preferences
                        if(myPreferenceManager.isFirstLaunch()){
                            reRegisterGCM(nam,ema);
                            myPreferenceManager.setIsFirstLaunch(false);

                        }
                        MyApplication.getInstance().getPrefManager().storeUser(user);
                        startActivity(new Intent(getApplicationContext(), MapsActivity.class));
                        finish();

                    } else {
                        // login error - simply toast the message
                        loading.dismiss();
                        AlertDialog.Builder builder = new AlertDialog.Builder(context);
                        builder.setTitle("Invalid credentials").setCancelable(false)
                                .setMessage("Please try again")
                                .setNegativeButton("Retry", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        //retry
                                        dialogInterface.dismiss();
                                    }
                                });
                        builder.show();

                        //Toast.makeText(getApplicationContext(), "" + obj.getJSONObject("error").getString("message"), Toast.LENGTH_LONG).show();
                    }

                } catch (JSONException e) {
                    Log.e(TAG, "json parsing error: " + e.getMessage());
                    Toast.makeText(getApplicationContext(), "Json parse error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                NetworkResponse networkResponse = error.networkResponse;
                loading.dismiss();
                Log.e(TAG, "Volley error: " + error.getMessage() + ", code: " + networkResponse+" and "+error.getMessage());
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle("Error").setCancelable(false)
                        .setMessage("Please check your internet settings and try again")
                        .setNeutralButton("Open settings", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent myIntent = new Intent(Settings.ACTION_SETTINGS);
                               startActivity(myIntent);
                            }
                        })
                        .setNegativeButton("Retry", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                //retry
                             login();
                            }
                        });
                builder.show();
               //Toast.makeText(getApplicationContext(), "Volley error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }) {

            @Override

            public Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("email",email);
                params.put("password",password);

                Log.e(TAG, "params: " + params.toString());
                return params;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String,String> params = new HashMap<String, String>();
                params.put("Content-Type","application/x-www-form-urlencoded");
                return params;
            }
        };
        //Adding request to request queue
        MyApplication.getInstance().addToRequestQueue(strReq);
    }

切换到我的dualsim(The logcat)上的另一个simcard后遇到以下错误

01-08 07:59:36.143 1305-1342/mushirih.up I/[MALI][Gralloc]: [+]r_hnd(0x7fa19abe60), client(35), share_fd(63)
01-08 07:59:36.427 1305-1428/mushirih.up I/System.out: close [socket][/196.103.96.143:44803]
01-08 07:59:36.428 1305-1428/mushirih.up E/Volley: [3020] BasicNetwork.performRequest: Unexpected response code 404 for http://xxx/v1/user/login
01-08 07:59:36.450 1305-1342/mushirih.up I/[MALI][Gralloc]: [-]r_hnd(0x7fa19abd20), client(35), share_fd(55)
01-08 07:59:36.451 1305-1342/mushirih.up I/[MALI][Gralloc]: [-]r_hnd(0x7f8fc20640), client(35), share_fd(61)
01-08 07:59:36.452 1305-1342/mushirih.up I/[MALI][Gralloc]: [-]r_hnd(0x7fa19abe60), client(35), share_fd(63)
01-08 07:59:36.452 1305-1342/mushirih.up I/[MALI][Gralloc]: [-]r_hnd(0x7fa19ac2c0), client(35), share_fd(56)
01-08 07:59:36.457 1305-1305/mushirih.up E/MainActivity.class: Volley error: null, code: com.android.volley.NetworkResponse@e26bc80 and null
01-08 07:59:36.504 1305-1342/mushirih.up W/libEGL: [ANDROID_RECORDABLE] format: 1
4

0 回答 0