Pregunta

Así que estoy trabajando en un CouchDB Gui Caja de herramientas para el mantenimiento de un entorno más fácil hasta CouchDB en Android, como futón es bastante incómodo en un pequeño dispositivo móvil.

Yo quería que se adhieren a la "org.apache.http.client. *" Paquetes de este, que estaba funcionando bastante bien hasta que me quería administradores de configuración ..

Con la herramienta de línea de comandos "rizo" funciona como un encanto:

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

Pero sigo teniendo grandes problemas que traducen a un método "org.apache.http.client.methods.HttpPut ()".

Cualquier ayuda apreciada.

¿Fue útil?

Solución

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

Otros consejos

Sí, lo siento. Sólo para completar la respuesta, aquí es cómo tratar efectivamente con la respuesta que me pasa por la solicitud:

    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();  
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top