The following is my code for a HTTP POST request in an Android device running Android 4.1.2. I have question:
This code works perfectly on a Samsung device whereas it is giving "Content-type is not application/json" on an HTC device.
public static String POST(String url, JSONObject obj) { Log.i("JSONPOSTBEGIN", "Beginning of JSON POST"); InputStream inputStream = null; String result = "";
HttpClient httpclient = new DefaultHttpClient(); try { HttpPost post = new HttpPost(url); post.setHeader("Content-type", "application/json"); post.setHeader("Accept", "application/json"); StringEntity se = new StringEntity(obj.toString()); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(se); HttpResponse httpResponse = mHhttpclient.execute(post); // receive response as inputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if(inputStream != null) { result = convertInputStreamToString(inputStream); } else result = "Did not work!"; } catch (Exception e) { Log.d("InputStream", e.getLocalizedMessage()); } Log.i("JSONPOSTEND", "End of JSON data post methos..."); return result;}