Apacheのhttpclientを介してCouchDBで管理者をセットアップする方法(カールの例が与えられます)

StackOverflow https://stackoverflow.com/questions/4188621

質問

したがって、AndroidでのCouchDBのセットアップを簡単に維持できるように、CouchDB GUIツールボックスに取り組んでいます。

「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