/** * Add the HTTP header field associated with the provided key and value. * * @param key The header's key. * @param value The header's value. * @throws ParseException if anything goes wrong. */ public void addHeader(final String key, final String value) throws ParseException { try { headers.put(key, value); } catch (JSONException ex) { Logger.getInstance().error("Unable to add header. Error: " + ex); throw new ParseException( ParseException.INVALID_JSON, ParseException.ERR_PREPARING_REQUEST, ex); } }
/** * Adds the default headers (e.g., {@link ParseConstants#HEADER_APPLICATION_ID} and {@link * ParseConstants#HEADER_CLIENT_KEY}) associated with Parse REST API calls. * * @param addJson If true, the corresponding content-type header field is also set. * @throws ParseException if anything goes wrong. */ protected void setupDefaultHeaders(boolean addJson) throws ParseException { try { headers.put(ParseConstants.HEADER_APPLICATION_ID, Parse.getApplicationId()); headers.put(ParseConstants.HEADER_CLIENT_KEY, Parse.getClientKey()); if (addJson) { headers.put(ParseConstants.HEADER_CONTENT_TYPE, ParseConstants.CONTENT_TYPE_JSON); } if (!data.has(ParseConstants.FIELD_SESSION_TOKEN) && ParseUser.getCurrent() != null) { data.put(ParseConstants.FIELD_SESSION_TOKEN, ParseUser.getCurrent().getSessionToken()); } if (data.has(ParseConstants.FIELD_SESSION_TOKEN)) { headers.put( ParseConstants.HEADER_SESSION_TOKEN, data.getString(ParseConstants.FIELD_SESSION_TOKEN)); } } catch (JSONException ex) { throw new ParseException( ParseException.INVALID_JSON, ParseException.ERR_PREPARING_REQUEST, ex); } }