android - 出现409错误无法解决我该如何解决

标签 android exception error-handling runtime-error android-volley

E/Volley: [19528] BasicNetwork.performRequest: Unexpected response code 409 for http://13.232.142.23:3000/api/register



如果用户已经注册并且otp不正确,但是我在注册时有一些代码可以发出警报,但是如果输入otp不正确或用户已经注册,则不会显示警报。有什么问题我无法得到它。

//registerUser(电话,otp,全名,电子邮件,密码,device_id);
    private void registerUser(final String phone,final String otp,final String fullname,final String email,  final String password, final String device_id )
    {

        Log.e(TAG, "otp12 " +otp11);

        String tag_string_req = "req_register";



        Map<String, String> params = new HashMap<String, String>();
        params.put("Content-Type", "application/json");



        params.put("phone",phone);
        params.put("otp",otp);
        params.put("fullname", fullname);
        params.put("email",email);


        params.put("password",password);

        params.put("device_id", device_id);

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                AppConfig.Base_Url+AppConfig.App_api+AppConfig.URL_REGISTER, new JSONObject(params),
                new Response.Listener<JSONObject>()

 {

                  @Override
                    public void onResponse(JSONObject response1) {

                Log.d(TAG, "Register Response: " + response1.toString());


                try {
                    JSONObject jObj = new JSONObject(String.valueOf(response1));
                    String response = jObj.getString("code");
                    String status =jObj.getString("status");
                    String message= jObj.getString("message");

                    Log.e(TAG, "r2222" + response);
                    Log.e(TAG, "status1: " + status);
                    Log.e(TAG,"Message"+message);
                    if (status!=null && status.equals("true")) {

                        launchAgeScreen();

                        Log.e(TAG, "123" + fullname);
                        Log.e(TAG, "status: " + status);
                        Log.e(TAG, "paswword: " + password);

                        Log.e(TAG, "response2163123: " + response);

                    }else if (status!=null && message.equals("user is already register"))
                    {
                        AlertDialog.Builder builder =new AlertDialog.Builder(RegisterActivity.this);
                        builder.setTitle("Registration Error");
                        builder.setMessage("You have already registered with FeeDeposit. Please click Okay to Login");
                        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(RegisterActivity.this,LoginActivityWithoutSharedPreference.class);
                                startActivity(intent);
                            }
                        });
                        AlertDialog alertDialog = builder.create();
                        alertDialog.show();

                    }


                    else if (status!=null && message.equals("invalid otp"))
                    {

                        AlertDialog alertDialog = new AlertDialog.Builder(RegisterActivity.this, R.style.MyDialogTheme).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("OTP ");

                        // Setting Dialog Message
                        alertDialog.setMessage("Invalid OTP");

                        // Setting Icon to Dialog
                        //  alertDialog.setIcon(R.drawable.tick);

                        // Setting OK Button
                        alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Write your code here to execute after dialog closed
                                // Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                            }
                        });

                        alertDialog.show();

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    //Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {

                if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                    AlertDialog alertDialog = new AlertDialog.Builder(RegisterActivity.this, R.style.MyDialogTheme).create();

                    // Setting Dialog Title
                    alertDialog.setTitle("Network/Connection Error");

                    // Setting Dialog Message
                    alertDialog.setMessage("Internet Connection is poor OR The Server is taking too long to respond.Please try again later.Thank you.");

                    // Setting Icon to Dialog
                    //  alertDialog.setIcon(R.drawable.tick);

                    // Setting OK Button
                    alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // Write your code here to execute after dialog closed
                            // Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                        }
                    });

                    // Showing Alert Message
                    alertDialog.show();
                   // Log.e(TAG, "Registration Error: " + error.getMessage());
                    /*Toast.makeText(context,
                            context.getString(R.string.error_network_timeout),
                            Toast.LENGTH_LONG).show();*/
                } /*else if (error instanceof AuthFailureError) {
                    //TODO
                } else if (error instanceof ServerError) {
                    //TODO
                } else if (error instanceof NetworkError) {
                    //TODO
                } else if (error instanceof ParseError) {
                    //TODO
                }
*/



            }
        }) /*{

            @Override
            protected Map<String, String> getParams() throws AuthFailureError{
                // Posting params to register url

                Map<String, String> params = new HashMap<String, String>();
                params.put("Content-Type", "application/json");



                params.put("phone",phone);
                params.put("otp",otp);
                params.put("fullname", fullname);
                params.put("email",email);


                params.put("password",password);

                params.put("device_id", device_id);




                return params;
            }

        }*/;






        jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
                MY_SOCKET_TIMEOUT_MS,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            try {
                ProviderInstaller.installIfNeeded(getApplicationContext());
            } catch (GooglePlayServicesRepairableException e) {
                // Indicates that Google Play services is out of date, disabled, etc.
                // Prompt the user to install/update/enable Google Play services.
                GooglePlayServicesUtil.showErrorNotification(e.getConnectionStatusCode(), getApplicationContext());
                // Notify the SyncManager that a soft error occurred.
                //final SyncResult syncResult = null;
                //syncResult.stats.numIOExceptions++;

                //Toast.makeText(getApplicationContext(), "Sync", Toast.LENGTH_LONG).show();
                return;
            } catch (GooglePlayServicesNotAvailableException e) {
                // Indicates a non-recoverable error; the ProviderInstaller is not able
                // to install an up-to-date Provider.
                // Notify the SyncManager that a hard error occurred.
                //syncResult.stats.numAuthExceptions++;
               // Toast.makeText(getApplicationContext(), "Sync12", Toast.LENGTH_LONG).show();
                return;
            }

            HttpStack stack = null;
            try {
                stack = new HurlStack(null, new TLSSocketFactory());
            } catch (KeyManagementException e) {
                e.printStackTrace();
                Log.d("Your Wrapper Class", "Could not create new stack for TLS v1.2");
                stack = new HurlStack();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                Log.d("Your Wrapper Class", "Could not create new stack for TLS v1.2");
                stack = new HurlStack();
            }

             Appcontrol.getInstance().addToRequestQueue(jsonObjReq, tag_string_req);
           // AppController.getInstance().addToRequestQueue(getApplicationContext(),stack);

            requestQueue = Volley.newRequestQueue(getApplicationContext(), stack);
        } else {

            requestQueue = Volley.newRequestQueue(getApplicationContext());
            //AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
        }

        Appcontrol.getInstance().addToRequestQueue(jsonObjReq, tag_string_req);




        // Adding request to request queue
      //
        //
        //
        //
        //
        //AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
    }

最佳答案

解决方案是将urlt php文件的URL地址重命名为register.php中的registerAccount.php。错误409冲突是由使用预定义变量引起的客户端错误,它发生在某些网络上。
希望对您有帮助

关于android - 出现409错误无法解决我该如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54523315/

相关文章:

Android Room Embedded Relation忽略where条件

java - 包中抛出特定异常的所有方法的列表

excel - VBA无法打开文件时的备用消息

php - php mysql如何解决此错误:Undefined variable :id in C:\

android - 查找市场上所有 Android 应用程序的列表

android - 使用 LibGdx 创建 Facebook 游戏请求

c++ - 异常、 move 语义和优化 : at compiler's mercy (MSVC2010)?

php - 将file_get_contents与错误的代理一起使用时,如何处理500个内部服务器错误?

android - 如何从另一个模块调用layout xml

java - SQL Server SET XACT_ABORT ON 和 JAVA