Arduino Uno



JSON request

If you want to do a JSON request in Android, a working way I ended up is this one:

		// define some input variables
		String url = "";
		String json = " ... // your JSON string // ...";
		// prepare the client
		HttpParams httpParams = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
		HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
		HttpClient client = new DefaultHttpClient(httpParams);
		// prepare the request
		HttpPost request = new HttpPost(url);
		ByteArrayEntity bae = new ByteArrayEntity(json.toString().getBytes("UTF-8"));
		bae.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
		ResponseHandler responseHandler = new BasicResponseHandler();
		// execute the request and get back the response
		String responseBody = client.execute(request,responseHandler);