Java 如何通过Apache';s HttpClient(给出了一个curl示例)
因此,我正在开发CouchDB Gui工具箱,以便在Android上更轻松地维护CouchDB的设置,因为Futon在小型移动设备上非常不舒服 我想坚持使用“org.apache.http.client.*”包,在我想设置管理员之前,这个包一直运行得很好 使用命令行工具“curl”,它就像一个符咒:Java 如何通过Apache';s HttpClient(给出了一个curl示例),java,apache,couchdb,httpclient,android-syncadapter,Java,Apache,Couchdb,Httpclient,Android Syncadapter,因此,我正在开发CouchDB Gui工具箱,以便在Android上更轻松地维护CouchDB的设置,因为Futon在小型移动设备上非常不舒服 我想坚持使用“org.apache.http.client.*”包,在我想设置管理员之前,这个包一直运行得很好 使用命令行工具“curl”,它就像一个符咒: curl -X PUT http://127.0.0.1:5984/_config/admins/username -d '"password"' 但我一直在将其转换为“org.apache.ht
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();
}