Created
July 27, 2012 17:59
-
-
Save kristopherjohnson/3189389 to your computer and use it in GitHub Desktop.
Create a JSON POST request for Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create HttpPost request with a JSON string body, expecting a JSON response | |
*/ | |
private HttpPost createJSONPostRequest(String emailAddress, String data) throws JSONException, UnsupportedEncodingException | |
{ | |
JSONObject json = new JSONObject(); | |
json.put("protocolVersion", "1.0"); | |
json.put("emailAddress", emailAddress); | |
json.put("data", data); | |
String jsonString = json.toString(); | |
HttpPost request = new HttpPost(serviceURLString); | |
request.setHeader("Accept", "application/json"); | |
request.setHeader("Content-type", "application/json"); | |
request.setEntity(new StringEntity(jsonString)); | |
return request; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment