Android Volley BasicNetwork.performRequest()意外响应代码404 [英] Android Volley BasicNetwork.performRequest() unexpected response code 404

查看:318
本文介绍了Android Volley BasicNetwork.performRequest()意外响应代码404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用排球库发出网络请求时遇到此错误,我已经按照以下链接操作意外的响应代码是404 volley ,但是在我的情况下,它们都不起作用.这是我的请求代码

I am getting this error while making a network request using volley library,I have followed these links Android Volley - BasicNetwork.performRequest: Unexpected response code 400 and Unexpected response code 404 volley but none of them working in my case . Here is my request code

 StringRequest stringRequest = new StringRequest(Request.Method.POST,AppConstants.LOG_IN_API , new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d("TAG", "Login Response: " + response.toString());
                try {
                    JSONObject jsonObject = new JSONObject(response);
                   Log.v("USerid",""+jsonObject.getInt("userid"));

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                System.out.println("volley Error ................."+volleyError);
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
               Log.v("getparams","Is called");
                Map<String, String> params = new HashMap<String, String>();
                params.put(AppConstants.USER_ID, "info@mindtears.com");
                params.put(AppConstants.PASSWORD, "123456");
                return params;
            }


            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();

                headers.put("Content-Type", "application/json; charset=utf-8");
                return headers;
            }

        };

        Log.v("Request",""+stringRequest);

        AppController.getInstance().addToRequestQueue(stringRequest);

    }

有人可以告诉我我的代码在哪里做错了吗?任何帮助都是可观的.

Is there anyone who can tell me where I am doing wrong in my code? Any help is appreciable.

推荐答案

通常,此响应是通过使用URL发送错误的参数引起的.请检查每个参数的拼写,并确保是否以字符串或对象形式获得响应.还要检查内容类型.

Generally this response is caused by sending wrong parameters with the URL. Please check every parameter with spelling and make sure if response is obtained in string or in object. Also check Content-type.

希望这会对您有所帮助.
谢谢.

Hope this will help you.
Thank you.

这篇关于Android Volley BasicNetwork.performRequest()意外响应代码404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆