Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android,Java通过HttpClient-HttpPut_Java_Android_Node.js_Curl_Couchdb - Fatal编程技术网

Android,Java通过HttpClient-HttpPut

Android,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

我正在使用couchdb服务器端开发原生android应用程序。 每次我尝试将附件上传到文档时,都会抛出ClientProtocolException

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;

}