因此,我正在使用CouchDB GUI工具箱进行工作,以便在Android上更容易地维护设置CouchDB,因为Futon在小型移动设备上非常不舒服。

我想坚持使用“ org.apache.http.client。”此软件包,直到我想设置管理员。

使用命令行工具“ curl”,它像魅力一样工作:

curl -X PUT http://127.0.0.1:5984/_config/admins/username -d '"password"'

但是,我一直在将其转换为“ org.apache.http.client.methods.httpput()”方法时遇到很大的问题。

任何帮助都赞赏。

有帮助吗?

解决方案

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);

其他提示

是的,对不起。只是为了完成答案,这是如何实际处理我为请求得到的响应:

    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();  
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top