I am creating an Android application that stores data in CouchDB, and I need to create a database from an Android application. I need to execute the command "curl-X PUT http: // user: passwd@127.0.0.1 : 5984 / myDataBase " using java methods.
I implemented the following functions:
public static boolean createDatabase(String hostUrl, String databaseName) { try { HttpPut httpPutRequest = new HttpPut(hostUrl + databaseName); JSONObject jsonResult = sendCouchRequest(httpPutRequest); return jsonResult.getBoolean("ok"); } catch (Exception e) { e.printStackTrace(); } return false; } private static JSONObject sendCouchRequest(HttpUriRequest request) { try { HttpResponse httpResponse = (HttpResponse) new DefaultHttpClient().execute(request); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String resultString = convertStreamToString(instream); instream.close(); JSONObject jsonResult = new JSONObject(resultString); return jsonResult; } } catch (Exception e) { e.printStackTrace(); } return null; }
I call the function:
createDatabase("http://user: passwd@127.0.0.1 /","myDataBase");
but there is no result. I think the problem is in the user: passwd, because in the "admin party" mode the function works fine, calling:
createDatabase("http://127.0.0.1/","myDataBase");
source share