Skip to content

Instantly share code, notes, and snippets.

@mochico
Created December 10, 2013 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mochico/7886338 to your computer and use it in GitHub Desktop.
Save mochico/7886338 to your computer and use it in GitHub Desktop.
public class MyJsonObjectRequest extends JsonObjectRequest {
private MyJsonObjectRequest(int method, String url,
JSONObject jsonRequest, Listener<JSONObject> listener,
ErrorListener errorListener) {
super(method, url, jsonRequest, listener, errorListener);
}
public MyJsonObjectRequest(String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener) {
super(url, jsonRequest, listener, errorListener);
}
@Override
protected Response<JSONObject> parseNetworkResponse(
NetworkResponse response) {
Map<String, String> headers = response.headers;
if (headers.containsKey(Constants.SET_COOKIE)) {
mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
.edit()
.putString(PREF_SAVED_COOKIE, headers.get("Set-Cookie"))
.commit();
}
return super.parseNetworkResponse(response);
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> customHeaders = super.getHeaders();
Map<String, String> newHeaders = new HashMap<String, String>();
newHeaders.putAll(customHeaders);
String cookieStr = mContext.getSharedPreferences(PREF_NAME,
Context.MODE_PRIVATE).getString(PREF_SAVED_COOKIE, "");
if (cookieStr.length() > 0) {
newHeaders.put("cookie", cookieStr);
}
return newHeaders;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment