Come amministratori di installazione in CouchDB via Apache di HttpClient (dato un esempio ricciolo)
-
10-10-2019 - |
Domanda
Quindi, sto lavorando su un CouchDB Gui Toolbox per facilitare il mantenimento di un ambiente fino CouchDB su Android, come Futon è abbastanza scomodo su un piccolo dispositivo mobile.
Ho voluto aderire al "org.apache.http.client. *" Pacchetti per questo che stava lavorando abbastanza bene fino a quando ho voluto amministratori di impostazione ..
Con lo strumento a riga di comando "ricciolo" funziona come un fascino:
curl -X PUT http://127.0.0.1:5984/_config/admins/username -d '"password"'
Ma io continuo a avere grossi problemi traduzione che a un metodo "org.apache.http.client.methods.HttpPut ()".
Qualsiasi aiuto apprezzato.
Soluzione
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);
Altri suggerimenti
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();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow