So I am working on a CouchDB Gui Toolbox for easier maintaining an setting up CouchDB on Android, as Futon is quite uncomfortable on a small mobile device.
I wanted to stick to the "org.apache.http.client.*" packages for this which was working out quite well until I wanted to setup administrators..
With the commandline tool "curl" it works like a charm:
curl -X PUT http://127.0.0.1:5984/_config/admins/username -d '"password"'
But I keep on having big problems translating that to a "org.apache.http.client.methods.HttpPut()" method.
Any help appreciated.
DefaultHttpClient client = new DefaultHttpClient();
HttpPut put = new HttpPut("http://127.0.0.1:5984/_config/admins/username");
put.setEntity(new StringEntity("\"password\""));
client.execute(put);
Yes, sorry. Just to complete the answer, here's how to actually deal with the response I get for the request:
DefaultHttpClient client = new DefaultHttpClient();
JSONObject json = null;
HttpPut put = new HttpPut("http://127.0.0.1:5984/_config/admins/username");
try {
StringEntity strEntity = new StringEntity("\"" + password + "\"");
put.setEntity(strEntity);
response = client.execute(put);
HttpEntity responseEntity = response.getEntity();
//Or do something with the entity of the response
// if (response.getStatusLine().getStatusCode() == 200) {
// return something;
// }
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}