📌  相关文章
📜  如何使用 volley 将 json 数据发送到 android 中的服务器 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:53.894000             🧑  作者: Mango

代码示例1
RequestQueue queue = Volley.newRequestQueue(this);

  private void makeJsonObjReq() {
    showProgressDialog();


            Map postParam= new HashMap();
            postParam.put("un", "xyz@gmail.com");
            postParam.put("p", "somepasswordhere");


    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
            Const.URL_LOGIN, new JSONObject(postParam),
            new Response.Listener() {

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

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hideProgressDialog();
                }
            }) {

        /**
         * Passing some request headers
         * */
        @Override
        public Map getHeaders() throws AuthFailureError {
            HashMap headers = new HashMap();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }



    };

    jsonObjReq.setTag(TAG);
    // Adding request to request queue
    queue.add(jsonObjReq);

    // Cancelling request
    /* if (queue!= null) {
    queue.cancelAll(TAG);
    } */

}