Android - Put/get request
I'm starting with Couchbase. I'm trying to make a put/get request from Android device to server with sync gateway.
I've tried like I make in CouchDB:
HttpClient httpClient = new DefaultHttpClient(); HttpPut put = new HttpPut("http://IP:4984/BUCKET"); put.setHeader("content-type", "application/json"); JSONObject oNode = new JSONObject(); oNode.put("field", "test"); StringEntity entity = new StringEntity(oNode.toString()); put.setEntity(entity); HttpResponse resp = httpClient.execute(put);
But it doesn't work.
I've been looking for, but I'm not be able to find anything about how to do it. How can I do it?
Next, I'll test design documents with update functions, like CouchDB. Does it work in Couchbase server?
Thank you very much.
I am not sure to understand exactly what you are doing, but let me clarify some things.
1- If you are using Couchbase Lite (Couchbase on your mobile http://mobile.couchbase.com ) you have to use the local Android API and let the system synchronize with your Couchbase cluster using the Sync Gateway. You are not responsible of the "get/put" from the cluster this is done by the gateway
2- If you want to push date directly from your Android phone to the Couchbase cluster, (so you do not store any data on your mobile in Couchbase), you cannot use the gateway for that, it is not made for that. You have to create your own REST interface to get/put/delete data from your database.