Volley无法将标头参数托管到服务器

时间:2019-01-06 03:45:07

标签: android-studio android-volley

Volley标头未托管到服务器,我尝试使用另一个库运行正常。但排球不起作用

                String url = "https://www.vperfumes.ae/index.php?route=rest/cart/cart";

StringRequest stringRequest =新的StringRequest(Request.Method.GET,URL,新的Response.Listener(){                         @Override                         public void onResponse(String response){                             Log.e(“ onResponseSuccess”,response.toString()+“ check”);

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("onResponseSuccess", error.toString() +"check");

                    }
                }) {
                    @Override
                    public Map<String, String> getHeaders() throws AuthFailureError {
                        Map<String, String> headers = new HashMap<>();
                        headers.put("Content-Type", "application/json; ");
                        String user_email;
                        if (SharedPrefence.getUserEmail(mContext) != null) {
                            user_email = SharedPrefence.getUserEmail(mContext);
                        } else {
                            user_email = "";
                        }
                        headers.put("x-oc-useremail", user_email);
                        headers.put("X-Oc-Session", "1c4a8becc9bd2fc7abd2dc1dbc79e638");
                        try {
                            headers.putAll(super.getHeaders());
                        } catch (AuthFailureError authFailureError) {
                            authFailureError.printStackTrace();
                        }
                        return super.getHeaders();
                    }
                };
                Volley.newRequestQueue(mContext).add(stringRequest);

0 个答案:

没有答案