Как настроить администраторы в CouchDB через HttpClient Apache (приведенный примером Curl)
-
10-10-2019 - |
Вопрос
Поэтому я работаю над инструментом CouchDB GUI, чтобы облегчить поддержание настройки CouchDB на Android, так как Footon довольно неудобен на небольшом мобильном устройстве.
Я хотел придерживаться пакетов "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