Android,Java通过HttpClient-HttpPut
我正在使用couchdb服务器端开发原生android应用程序。 每次我尝试将附件上传到文档时,都会抛出ClientProtocolExceptionAndroid,Java通过HttpClient-HttpPut,java,android,node.js,curl,couchdb,Java,Android,Node.js,Curl,Couchdb,我正在使用couchdb服务器端开发原生android应用程序。 每次我尝试将附件上传到文档时,都会抛出ClientProtocolException public JSONObject uploadPicture(PutAttachment putAttachment) { JSONObject obj = null; try { HttpClient httpclient = new DefaultHttpClient(); HttpPut h
public JSONObject uploadPicture(PutAttachment putAttachment) {
JSONObject obj = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPut httpPut = new HttpPut(baseUrl() + putAttachment.getDbName() + "/" + putAttachment.getDocName() + "/attachment?rev=" + putAttachment.getRev());
ByteArrayEntity img = new ByteArrayEntity(putAttachment.getByteImg());
httpPut.setEntity(img);
httpPut.setHeader("Content-Length", "" + (int) img.getContentLength());
httpPut.setHeader("Content-type", "image/png");
httpPut.setHeader(authenticate());
HttpResponse response = httpclient.execute(httpPut);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
obj = new JSONObject(convertStreamToString(instream));
instream.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return obj;
}