*/
public String performAPIPostOperation(String apiURL, int expectedResponse, String input)
throws Exception
{
DefaultHttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost(apiURL);
try
{
method.setEntity(new StringEntity(input,ContentType.create("text/plain","UTF-8")));
HttpResponse response = client.execute(method);
int responseCode = response.getStatusLine().getStatusCode();
String responseString = convertToString(response);
if (responseCode != expectedResponse)
throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+", saw "+Integer.toString(responseCode)+": "+responseString);
// We presume that the data is utf-8, since that's what the API uses throughout.
return responseString;
}
finally
{
method.abort();
}
}