Apacheのhttpclientを介してCouchDBで管理者をセットアップする方法(カールの例が与えられます)
-
10-10-2019 - |
質問
したがって、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();
}
所属していません StackOverflow