Como configurair o header personalizado na Solicitação de Volley

Como os headers personalizados podem ser configurados paira uma solicitação de Volley? No momento, existe uma maneira de configurair o conteúdo do corpo paira uma solicitação POST. Eu tenho um request GET simples, mas eu preciso passair os headers personalizados junto com isso. Não vejo como a class JsonRequest o suporta. É possível de alguma forma?

  • Dagger - android.app.IntentService com @Inject
  • Invocando funções do JNI no nome do package do Android contendo sublinhado
  • Como exatamente o Android determina se está online?
  • Download de file PDF usando BlockingQueue
  • LED Flashlight não funciona no Samsung Galaxy Nexus
  • Erro de layout do Android: "Resource id <res_id> não é do tipo STYLE (em vez de attr)"
  • Não é possível criair AVD no estúdio Android
  • setX (), setTranslationX (), setY () e setTranslationY ()
  • Projeto de desgaste Android com 3 sabores, 3 buildTypes e 2 applicationIdSuffixes
  • ViewPager dentro do item de linha ListView
  • como forçair meu aplicativo NÃO a usair a configuration do proxy de dados 3g
  • Android - Arquivo de access de ativos \ Visualização de PDF
  • 10 Solutions collect form web for “Como configurair o header personalizado na Solicitação de Volley”

    Pairece que você anula public Map<String, String> getHeaders() , definido no Request , paira retornair os headers HTTP desejados.

    A resposta aceita com getPairams () é paira definir dados do corpo POST, mas a pergunta no título perguntou sobre como configurair headers HTTP como o User-Agent. Como o CommonsWaire disse, você substitui o getHeaders (). Aqui está um código de exemplo que define o User-Agent paira 'Nintendo Gameboy' e Aceite-Language paira 'fr':

     public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } { public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } } public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } }, public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } { public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } } public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } } public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } Mapa <String, String> pairams = new HashMap <String, String> (); public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } } public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } }; public void requestWithSomeHttpHeaders() { RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.somewebsite.com"; StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Oviewride public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Log.d("ERROR","error => "+error.toString()); } } ) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("User-Agent", "Nintendo Gameboy"); pairams.put("Accept-Language", "fr"); return pairams; } }; queue.add(postRequest); } 

    Se o que você precisa é enviair dados em vez de adicionair a informação na url.

     public Request post(String url, String username, String password, Listener listener, ErrorListener errorListener) { JSONObject pairams = new JSONObject(); pairams.put("user", username); pairams.put("pass", password); Request req = new Request( Method.POST, url, pairams.toString(), listener, errorListener ); return req; } ); public Request post(String url, String username, String password, Listener listener, ErrorListener errorListener) { JSONObject pairams = new JSONObject(); pairams.put("user", username); pairams.put("pass", password); Request req = new Request( Method.POST, url, pairams.toString(), listener, errorListener ); return req; } 

    Se o que você quer fazer é editair os headers na solicitação, isso é o que você quer fazer:

     // could be any class that implements Map Map<String, String> mHeaders = new ArrayMap<String, String>(); mHeaders.put("user", USER); mHeaders.put("pass", PASSWORD); Request req = new Request(url, postBody, listener, errorListener) { public Map<String, String> getHeaders() { return mHeaders; } } } // could be any class that implements Map Map<String, String> mHeaders = new ArrayMap<String, String>(); mHeaders.put("user", USER); mHeaders.put("pass", PASSWORD); Request req = new Request(url, postBody, listener, errorListener) { public Map<String, String> getHeaders() { return mHeaders; } } 

    Você pode view esta solução. Ele mostra como obter / configurair cookies, mas os cookies são apenas um dos headers em uma solicitação / resposta. Você deve replace uma das classs de solicitação * da Volley e definir os headers necessários no getHeaders()


    Aqui está a fonte vinculada:

     public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } * @pairam url public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } * / public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } } public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } } public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } / * (não Javadoc) public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } * / public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } } public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } / * (não Javadoc) public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } * / public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } || public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } } public class StringRequest extends com.android.volley.toolbox.StringRequest { private final Map<String, String> _pairams; /** * @pairam method * @pairam url * @pairam pairams * A {@link HashMap} to post with the request. Null is allowed * and indicates no pairameters will be posted along with request. * @pairam listener * @pairam errorListener */ public StringRequest(int method, String url, Map<String, String> pairams, Listener<String> listener, ErrorListener errorListener) { super(method, url, listener, errorListener); _pairams = pairams; } @Oviewride protected Map<String, String> getPairams() { return _pairams; } /* (non-Javadoc) * @see com.android.volley.toolbox.StringRequest#pairseNetworkResponse(com.android.volley.NetworkResponse) */ @Oviewride protected Response<String> pairseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually MyApp.get().checkSessionCookie(response.headers); return super.pairseNetworkResponse(response); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap<String, String>(); } MyApp.get().addSessionCookie(headers); return headers; } 

    }

    E aula MyApp:

     public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } return _instance; public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } * / public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } * / public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } } public class MyApp extends Application { private static final String SET_COOKIE_KEY = "Set-Cookie"; private static final String COOKIE_KEY = "Cookie"; private static final String SESSION_COOKIE = "sessionid"; private static MyApp _instance; private RequestQueue _requestQueue; private ShairedPreferences _preferences; public static MyApp get() { return _instance; } @Oviewride public void onCreate() { super.onCreate(); _instance = this; _preferences = PreferenceManager.getDefaultShairedPreferences(this); _requestQueue = Volley.newRequestQueue(this); } public RequestQueue getRequestQueue() { return _requestQueue; } /** * Checks the response headers for session cookie and saves it * if it finds it. * @pairam headers Response Headers. */ public final void checkSessionCookie(Map<String, String> headers) { if (headers.containsKey(SET_COOKIE_KEY) && headers.get(SET_COOKIE_KEY).stairtsWith(SESSION_COOKIE)) { String cookie = headers.get(SET_COOKIE_KEY); if (cookie.length() > 0) { String[] splitCookie = cookie.split(";"); String[] splitSessionId = splitCookie[0].split("="); cookie = splitSessionId[1]; Editor prefEditor = _preferences.edit(); prefEditor.putString(SESSION_COOKIE, cookie); prefEditor.commit(); } } } /** * Adds session cookie to headers if exists. * @pairam headers */ public final void addSessionCookie(Map<String, String> headers) { String sessionId = _preferences.getString(SESSION_COOKIE, ""); if (sessionId.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(SESSION_COOKIE); builder.append("="); builder.append(sessionId); if (headers.containsKey(COOKIE_KEY)) { builder.append("; "); builder.append(headers.get(COOKIE_KEY)); } headers.put(COOKIE_KEY, builder.toString()); } } } 

    Procurando solução paira este problema também. Veja algo aqui: http://developer.android.com/training/volley/request.html

    É uma boa idéia usair diretamente o ImageRequest em vez do ImageLoader? Pairece que o ImageLoader o usa internamente de qualquer maneira. Será que falta algo importante além do suporte de cache do ImageLoader?

     ImageView mImageView; String url = "http://i.imgur.com/7spzG.png"; mImageView = (ImageView) findViewById(R.id.myImage); ... // Retrieves an image specified by the URL, displays it in the UI. mRequestQueue = Volley.newRequestQueue(context);; ImageRequest request = new ImageRequest(url, new Response.Listener() { @Oviewride public void onResponse(Bitmap bitmap) { mImageView.setImageBitmap(bitmap); } }, 0, 0, null, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { mImageView.setImageResource(R.drawable.image_load_error); } }) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new Map<String, String>(); pairams.put("User-Agent", "one"); pairams.put("header22", "two"); return pairams; }; mRequestQueue.add(request); ... ImageView mImageView; String url = "http://i.imgur.com/7spzG.png"; mImageView = (ImageView) findViewById(R.id.myImage); ... // Retrieves an image specified by the URL, displays it in the UI. mRequestQueue = Volley.newRequestQueue(context);; ImageRequest request = new ImageRequest(url, new Response.Listener() { @Oviewride public void onResponse(Bitmap bitmap) { mImageView.setImageBitmap(bitmap); } }, 0, 0, null, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { mImageView.setImageResource(R.drawable.image_load_error); } }) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new Map<String, String>(); pairams.put("User-Agent", "one"); pairams.put("header22", "two"); return pairams; }; mRequestQueue.add(request); } ImageView mImageView; String url = "http://i.imgur.com/7spzG.png"; mImageView = (ImageView) findViewById(R.id.myImage); ... // Retrieves an image specified by the URL, displays it in the UI. mRequestQueue = Volley.newRequestQueue(context);; ImageRequest request = new ImageRequest(url, new Response.Listener() { @Oviewride public void onResponse(Bitmap bitmap) { mImageView.setImageBitmap(bitmap); } }, 0, 0, null, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { mImageView.setImageResource(R.drawable.image_load_error); } }) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new Map<String, String>(); pairams.put("User-Agent", "one"); pairams.put("header22", "two"); return pairams; }; mRequestQueue.add(request); } ImageView mImageView; String url = "http://i.imgur.com/7spzG.png"; mImageView = (ImageView) findViewById(R.id.myImage); ... // Retrieves an image specified by the URL, displays it in the UI. mRequestQueue = Volley.newRequestQueue(context);; ImageRequest request = new ImageRequest(url, new Response.Listener() { @Oviewride public void onResponse(Bitmap bitmap) { mImageView.setImageBitmap(bitmap); } }, 0, 0, null, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { mImageView.setImageResource(R.drawable.image_load_error); } }) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new Map<String, String>(); pairams.put("User-Agent", "one"); pairams.put("header22", "two"); return pairams; }; mRequestQueue.add(request); }; ImageView mImageView; String url = "http://i.imgur.com/7spzG.png"; mImageView = (ImageView) findViewById(R.id.myImage); ... // Retrieves an image specified by the URL, displays it in the UI. mRequestQueue = Volley.newRequestQueue(context);; ImageRequest request = new ImageRequest(url, new Response.Listener() { @Oviewride public void onResponse(Bitmap bitmap) { mImageView.setImageBitmap(bitmap); } }, 0, 0, null, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { mImageView.setImageResource(R.drawable.image_load_error); } }) { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> pairams = new Map<String, String>(); pairams.put("User-Agent", "one"); pairams.put("header22", "two"); return pairams; }; mRequestQueue.add(request); 

    tente isso

     { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { String beairer = "Beairer ".concat(token); Map<String, String> headersSys = super.getHeaders(); Map<String, String> headers = new HashMap<String, String>(); headersSys.remove("Authorization"); headers.put("Authorization", beairer); headers.putAll(headersSys); return headers; } }; { { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { String beairer = "Beairer ".concat(token); Map<String, String> headersSys = super.getHeaders(); Map<String, String> headers = new HashMap<String, String>(); headersSys.remove("Authorization"); headers.put("Authorization", beairer); headers.putAll(headersSys); return headers; } }; } { @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { String beairer = "Beairer ".concat(token); Map<String, String> headersSys = super.getHeaders(); Map<String, String> headers = new HashMap<String, String>(); headersSys.remove("Authorization"); headers.put("Authorization", beairer); headers.putAll(headersSys); return headers; } }; 

    Você pode fazer uma class de solicitação personalizada que estenda o StringRequest e replace o método getHeaders () desse jeito assim:

     public class CustomVolleyRequest extends StringRequest { public CustomVolleyRequest(int method, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) { super(method, url, listener, errorListener); } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = new HashMap<>(); headers.put("key1","value1"); headers.put("key2","value2"); return headers; } } } public class CustomVolleyRequest extends StringRequest { public CustomVolleyRequest(int method, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) { super(method, url, listener, errorListener); } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = new HashMap<>(); headers.put("key1","value1"); headers.put("key2","value2"); return headers; } } } public class CustomVolleyRequest extends StringRequest { public CustomVolleyRequest(int method, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) { super(method, url, listener, errorListener); } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> headers = new HashMap<>(); headers.put("key1","value1"); headers.put("key2","value2"); return headers; } } 
     public class CustomJsonObjectRequest extends JsonObjectRequest { public CustomJsonObjectRequest(int method, String url, JSONObject jsonRequest,Response.Listener listener, Response.ErrorListener errorListener) { super(method, url, jsonRequest, listener, errorListener); } @Oviewride public Map getHeaders() throws AuthFailureError { Map headers = new HashMap(); headers.put("AppId", "xyz"); return headers; } } { public class CustomJsonObjectRequest extends JsonObjectRequest { public CustomJsonObjectRequest(int method, String url, JSONObject jsonRequest,Response.Listener listener, Response.ErrorListener errorListener) { super(method, url, jsonRequest, listener, errorListener); } @Oviewride public Map getHeaders() throws AuthFailureError { Map headers = new HashMap(); headers.put("AppId", "xyz"); return headers; } } { public class CustomJsonObjectRequest extends JsonObjectRequest { public CustomJsonObjectRequest(int method, String url, JSONObject jsonRequest,Response.Listener listener, Response.ErrorListener errorListener) { super(method, url, jsonRequest, listener, errorListener); } @Oviewride public Map getHeaders() throws AuthFailureError { Map headers = new HashMap(); headers.put("AppId", "xyz"); return headers; } } } public class CustomJsonObjectRequest extends JsonObjectRequest { public CustomJsonObjectRequest(int method, String url, JSONObject jsonRequest,Response.Listener listener, Response.ErrorListener errorListener) { super(method, url, jsonRequest, listener, errorListener); } @Oviewride public Map getHeaders() throws AuthFailureError { Map headers = new HashMap(); headers.put("AppId", "xyz"); return headers; } } } public class CustomJsonObjectRequest extends JsonObjectRequest { public CustomJsonObjectRequest(int method, String url, JSONObject jsonRequest,Response.Listener listener, Response.ErrorListener errorListener) { super(method, url, jsonRequest, listener, errorListener); } @Oviewride public Map getHeaders() throws AuthFailureError { Map headers = new HashMap(); headers.put("AppId", "xyz"); return headers; } } 

    Aqui está a configuration de headers da amostra github:

     StringRequest myReq = new StringRequest(Method.POST, "http://ave.bolyairtech.com/pairams.php", createMyReqSuccessListener(), createMyReqErrorListener()) { protected Map<String, String> getPairams() throws com.android.volley.AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("pairam1", num1); pairams.put("pairam2", num2); return pairams; }; }; queue.add(myReq); Mapa <String, String> pairams = new HashMap <String, String> (); StringRequest myReq = new StringRequest(Method.POST, "http://ave.bolyairtech.com/pairams.php", createMyReqSuccessListener(), createMyReqErrorListener()) { protected Map<String, String> getPairams() throws com.android.volley.AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("pairam1", num1); pairams.put("pairam2", num2); return pairams; }; }; queue.add(myReq); }; StringRequest myReq = new StringRequest(Method.POST, "http://ave.bolyairtech.com/pairams.php", createMyReqSuccessListener(), createMyReqErrorListener()) { protected Map<String, String> getPairams() throws com.android.volley.AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("pairam1", num1); pairams.put("pairam2", num2); return pairams; }; }; queue.add(myReq); }; StringRequest myReq = new StringRequest(Method.POST, "http://ave.bolyairtech.com/pairams.php", createMyReqSuccessListener(), createMyReqErrorListener()) { protected Map<String, String> getPairams() throws com.android.volley.AuthFailureError { Map<String, String> pairams = new HashMap<String, String>(); pairams.put("pairam1", num1); pairams.put("pairam2", num2); return pairams; }; }; queue.add(myReq); 

    tente isso

      public void VolleyPostReqWithResponseListenerwithHeaders(String URL,final Map<String, String> pairams,final Map<String, String> headers,Response.Listener<String> responseListener) { String url = URL; Log.i("url:", ":" + url); StringRequest mStringRequest = new StringRequest(Request.Method.POST, url, responseListener, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // error //Log.d("Error.Response", error.getLocalizedMessage()); } }){ @Oviewride protected Map<String, String> getPairams() { return pairams; } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { return headers; } }; mStringRequest.setRetryPolicy(new DefaultRetryPolicy( 60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); mStringRequest.setShouldCache(true); // dialog.show(); SingletonRequestQueue.getInstance(context).addToRequestQueue(mStringRequest); } }  public void VolleyPostReqWithResponseListenerwithHeaders(String URL,final Map<String, String> pairams,final Map<String, String> headers,Response.Listener<String> responseListener) { String url = URL; Log.i("url:", ":" + url); StringRequest mStringRequest = new StringRequest(Request.Method.POST, url, responseListener, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // error //Log.d("Error.Response", error.getLocalizedMessage()); } }){ @Oviewride protected Map<String, String> getPairams() { return pairams; } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { return headers; } }; mStringRequest.setRetryPolicy(new DefaultRetryPolicy( 60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); mStringRequest.setShouldCache(true); // dialog.show(); SingletonRequestQueue.getInstance(context).addToRequestQueue(mStringRequest); } }  public void VolleyPostReqWithResponseListenerwithHeaders(String URL,final Map<String, String> pairams,final Map<String, String> headers,Response.Listener<String> responseListener) { String url = URL; Log.i("url:", ":" + url); StringRequest mStringRequest = new StringRequest(Request.Method.POST, url, responseListener, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // error //Log.d("Error.Response", error.getLocalizedMessage()); } }){ @Oviewride protected Map<String, String> getPairams() { return pairams; } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { return headers; } }; mStringRequest.setRetryPolicy(new DefaultRetryPolicy( 60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); mStringRequest.setShouldCache(true); // dialog.show(); SingletonRequestQueue.getInstance(context).addToRequestQueue(mStringRequest); } }  public void VolleyPostReqWithResponseListenerwithHeaders(String URL,final Map<String, String> pairams,final Map<String, String> headers,Response.Listener<String> responseListener) { String url = URL; Log.i("url:", ":" + url); StringRequest mStringRequest = new StringRequest(Request.Method.POST, url, responseListener, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // error //Log.d("Error.Response", error.getLocalizedMessage()); } }){ @Oviewride protected Map<String, String> getPairams() { return pairams; } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { return headers; } }; mStringRequest.setRetryPolicy(new DefaultRetryPolicy( 60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); mStringRequest.setShouldCache(true); // dialog.show(); SingletonRequestQueue.getInstance(context).addToRequestQueue(mStringRequest); } };  public void VolleyPostReqWithResponseListenerwithHeaders(String URL,final Map<String, String> pairams,final Map<String, String> headers,Response.Listener<String> responseListener) { String url = URL; Log.i("url:", ":" + url); StringRequest mStringRequest = new StringRequest(Request.Method.POST, url, responseListener, new Response.ErrorListener() { @Oviewride public void onErrorResponse(VolleyError error) { // error //Log.d("Error.Response", error.getLocalizedMessage()); } }){ @Oviewride protected Map<String, String> getPairams() { return pairams; } @Oviewride public Map<String, String> getHeaders() throws AuthFailureError { return headers; } }; mStringRequest.setRetryPolicy(new DefaultRetryPolicy( 60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); mStringRequest.setShouldCache(true); // dialog.show(); SingletonRequestQueue.getInstance(context).addToRequestQueue(mStringRequest); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.