How to send request Header is “Content-Type”:“application/json” when GET on Volley

后端 未结 4 1167
梦毁少年i
梦毁少年i 2021-01-18 01:02

I try to use GET on Volley , but i need send request to application/json .

I take a look for some answers , i try to use jsonBody , but it

4条回答
  •  有刺的猬
    2021-01-18 01:21

    Use String request instead of jsonrequest like this

                StringRequest loginMe = new StringRequest(Request.Method.GET, "http://114.35.246.42:2212/MobileApp/DEST_WebService.asmx/GetNews", new Response.Listener() {
    
                    @Override
                    public void onResponse(String response) {
    
                        System.out.println("LoginActivity -- onResponse --> " + response);
    
                        if (progressDialog != null) {
    
                            progressDialog.dismiss();
    
                        }
    
                        try {
    
                            JSONObject jsonObject = new JSONObject(response);
    
                        } catch (Exception e) {
    
                            CommonUtility.somethingWentWrongDialog(activity,
                                    "LoginActivity -- onResponse-- Exception --> ".concat(e.getMessage()));
    
                        }
                    }
                }, new Response.ErrorListener() {
    
                    @Override
                    public void onErrorResponse(VolleyError error) {
    
                        if (progressDialog != null) {
    
                            progressDialog.dismiss();
    
                        }
    
                        CommonUtility.somethingWentWrongDialog(activity,
                                "LoginActivity -- onErrorResponse --> ".concat(error.getMessage()));
    
                    }
                }) {
    
                    @Override
                    protected Map getParams() {
    
                        Map params = new HashMap<>();
    
    
                        System.out.println("LoginActivity -- LoginParams --> " + params.toString());
    
                        return params;
    
                    }
                };
    
                loginMe.setRetryPolicy(new DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    
                Volley.newRequestQueue(activity).add(loginMe);
    

提交回复
热议问题