在Volley Android

时间:2017-02-13 10:01:45

标签: java android json android-volley

我使用volley进行API调用。但getParams没有被调用。这是我的代码

 String tag_json_obj = "json_obj_req";
        String url = "http://api.androidhive.info/volley/person_object.json";

        final ProgressDialog pDialog = new ProgressDialog(this);
        pDialog.setMessage("Loading...");
        pDialog.show();

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                url, null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d(TAG, response.toString());
                        pDialog.hide();
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
                // hide the progress dialog
                pDialog.hide();
            }
        }) {

            @Override
            protected Map<String, String> getParams() {
                Log.e("params:","called");
                Map<String, String> params = new HashMap<String, String>();
                params.put("name", "Androidhive");
                params.put("email", "abc@androidhive.info");
                params.put("password", "password123");

                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Log.e("headers:","called");
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json");
                return headers;
            }

        };

        AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);

我在哪里做错了?我在getHeaders和getParams上写了日志。但只打印getHeaders中的日志。

0 个答案:

没有答案