I am trying to send JSON data from my Android application to the server. The database is MySQL and ROR is used for server-side code. Below is the code used to send data.
try{ JSONObject json = new JSONObject(); json.put("id", "1"); json.put("catname", "gaurav"); json.put("catstart", "01012013"); json.put("catend", "01012013"); json.put("catvisible", "Y"); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, 5000); HttpClient client = new DefaultHttpClient(httpParams); String url = "http://192.168.1.9/3000/categories/create"; HttpPost request = new HttpPost(url); request.addHeader("Accept","application/json"); request.addHeader("Content-Type","application/json"); request.setEntity(new ByteArrayEntity(json.toString().getBytes( "UTF8")));
Here 192.168.1.9 is my computer IP address. During debugging in eclipse, I could see the values ββin the "request", but it threw an error when executing the last HttpResponse response = client.execute(request); . I am very new to this, so I'm not sure if I missed something. I am also trying to check the rails server if any request is received. Nothing started there. Please advise. Thanks.
source share