BasicNetwork.performRequest: Unexpected response code 500 for Volley

醉酒当歌 提交于 2019-12-13 03:44:56

问题


i am trying to create a user login page, i am getting this error while i try to register.I guess there is a problem with the Json object part.I tried searching for other answers in the forum but none of seem to address my problem. Request you to help me out with this. Thanks is advance.

 public void registercheck(final String name, final String email, final String password) {
    String tag_req = "Register_request";
    pdialog.setMessage("Registering ...");
    showDialog();

    StringRequest strR = new StringRequest(Request.Method.POST, Appconfig.LOGIN_URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            hidedialog();
            try {
                JSONObject jsp = new JSONObject(s);
                boolean error = jsp.getBoolean("error");
                if (!error) {
                    String uid = jsp.getString("uid");
                    JSONObject user = jsp.getJSONObject("user");
                    String name = user.getString("name");
                    String email = user.getString("email");
                    String created_at = user.getString("created_at");
                    db.addUser(name, email, uid, created_at);

                    session.setLogin(true);

                    Intent i = new Intent(Register.this, MainActivity.class);
                    startActivity(i);
                    finish();

                } else {
                    String error_msg = jsp.getString("error_msg");
                    Toast.makeText(Register.this, error_msg, Toast.LENGTH_LONG).show();

                }


            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            Log.e(TAG, volleyError.getMessage());
        }
    }) {

            @Override
        public Map<String, String> getParams() {
            Map<String, String> p = new HashMap<String, String>();
            p.put("name", name);
            p.put("tag", "register");
            p.put("email", email);
            p.put("password", password);

            return p;

My Log cat

15.407  11021-11440/example.com.login E/Volley﹕ [2407] BasicNetwork.performRequest: Unexpected response code 500 for http://busappandroid.gear.host/

回答1:


add header Content-Type - text/html. I tried to call your api from postman rest client without headers it will give error 500 after adding header to api got result 200 status ok




回答2:


myReq.setRetryPolicy(new DefaultRetryPolicy(10000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

Add this line before addidng your request in volley.

This is the minimum number of retries. Default is 1.



来源:https://stackoverflow.com/questions/35029609/basicnetwork-performrequest-unexpected-response-code-500-for-volley

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!