I'm trying to post data to a this webservice, but seems I cannot get this right! So Im trying to post json to the server but I dont know how to do that. I need to send this example json in order to get a json responce:
Content-Type : application/json HTTPMethod : POST HTTPBody : {"CouponVerificationCode":"594952223490","ApiKey":"zFyWQDYUKXQQpvG86snPD1OSslr7Q6DGEGbQ1f7P2YeTxB56y","Token":"_2_jx1YFvTZGGLNtJBoDW3gDZmNNAGpTWzT7dC6GrNAIkhhX9PWv75b776gq1ZO_2_SxMJjq8_2_kaDMyxX59HczOyaw=="}
but instead of getting a json responce i get html responce. Can someone please help me solve this issue?
This is the code im using to communicate with the server:
public static String makeRequest(String path) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(path);
JSONObject holder = new JSONObject();
// holder.accumulate(name, value)
String test = "{\"ApiKey\":\"somekey\","
+ "\"OperativeSystem\":\"0\","
+ "\"AppVersion\":\"1\","
+ "\"WebServiceVersion\":\"1\"}";
StringEntity se = new StringEntity(test);
Log.v("--", test);
httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
ResponseHandler responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httpost, responseHandler);
// HttpEntity entity = response.getEntity();
Log.v("--", response);
return response;
}