开发者

How to setup administrators in Couchdb via Apache's HttpClient (given a curl example)

开发者 https://www.devze.com 2023-01-25 19:42 出处:网络
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.

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..

W开发者_运维百科ith 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();  
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号