如何将base64字符串发布到服务器?

时间:2018-07-02 13:54:44

标签: android base64 http-post image-uploading

我正在尝试将base64字符串发布到服务器,并且它不会发布,可能是因为字符串太长而我收到了这个信息A connection to "server" was leaked. Did you forget to close a response body?

这是我的代码

try {

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            selectedImageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            selectedImageBitmap.recycle();
            byte[] byteFormat = stream.toByteArray();
            stream.close();
            stream = null;
            // get the base 64 string
            String imgString = Base64.encodeToString(byteFormat, Base64.DEFAULT);
            selectedImageBitmap=null;
            System.gc();
            byteFormat=null;
            System.gc();
            Log.d("image",""+ imgString);

            Log.d("urlnya", "" + LOGIN_URL);
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost post = new HttpPost(LOGIN_URL);
            HttpClient httpclientpost = new DefaultHttpClient();
            final HttpResponse responsepost = httpclientpost.execute(post);
            Log.d("respon post", "" + responsepost.getStatusLine().getStatusCode());
            post.addHeader("Content-Type", "application/json");
            JSONObject json = new JSONObject();

            json.put("user_id", 6);
            json.put("status", status_id);
            json.put("keterangan", ket);
            json.put("foto", imgString);


            Log.d("image",""+ encodedImage);

            StringEntity entity = new StringEntity(json.toString());
            post.setEntity(entity);
            HttpResponse responsepost2 = httpClient.execute(post);
            Log.d("respon post2", "" + responsepost2.getStatusLine().getStatusCode());
            // checking log for json response
            Log.d("processing ", json.toString());

        } catch (JSONException | IOException e) {
            e.printStackTrace();
        }

我已经尝试过发布base64了 /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAQ4B4ADASIA AhEBAxEB/8QAHwAAAAYDAQEBA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Nye+2w33H4/0weMOiQoniDMeUGfL+ W/xw1dBNuXL6TP3++GTid4G230n1wsaFQ9wHkkfjPPx/1woWUpWdIJEem/fvx2GEhQVKDp1HaRB2 439f9O8CMKVl2BKDKvP039f192I1xrST1O17fcW7jvOIV9CrzvtJm9/ToesfueNpgpSBulQJ4G3J EidvTCxthT4IBABgbcgz345O388Ji3pDhQTuTJI2gcCYgxhYUrICEBA321fKPIdzOGbnL3+/piGq VwQgjaDB9j9b/SOeFTaG9Sx6oJnYdzzyduMODTUxhCvUeXp6/P44QltStCxED3SOfie2HLt+l1DQ I/iTOwB7H9enzwrTpClAc567SRf09RyOIZwysn72wurKzqSAIkhvtHZPPP674eKw0klnggSZMdtP z/nhu7PTJIGhPujw5M9vd7/CP54ebL9IoBk6dhO0yeUeY49efXFny2m8wO8wetyUg8uff5Ww0Ugk XERz6ff3fC4tNAHAkgiPEjcD17fHn0w5Vqth1pIIiByE/wDMO0flgmsNFLYJb/4p843keX3wcPFZ 7P4i2h4UyEjYgd+OPId+/pONAyylUSAE3kbg9RF+REyN474aqsDPOw5X+vr9Ma7LalLca3EaiP4e fdgx8/PjD52qnKWo22SgcDsgev8ATBRZLK214RLJkA8wd/d/5RvtHPww4DFvUkEIbj7xsAPIYvFG 0mnbAMlSo6cgJgGDhg4FLPKBN+XL17fcYxYQqRHl98c/l85wcMI93fsfiCJP98bKajWmCURsN9z3 77eXy+WDFNIdQhEEwI34nmD/AKYdBwSrqSLcrb++/vywTwlRME9IHp/Xf7GLYmPIAT92Nim0qEED v2Eb+e2+ByKR3/JO2w3MfERjYmmVIlG8+Qj57YkWFnSB2t6Tsff+nqiW1EytMCPkbG8+uEvV2Jut B0kJO25QjsR3Injb8MNNmbJygiqbX4biVCPeDR2OraCD3EcRvMDEkE0a1bpTBHcGExvtI43ny/Hd J5ovuWbLQ1irjU06alpqSnU04dR1QCgrB/hUYIB+WHTiWVsrcqClptKCStawgEJSJgnewmCbbcpw NE1WLqG2aRp2peUtCW22G1OLBJ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/EzP/Jxhi4FImElXcX2j9Zj9JwlTvIbgFJE ETO02FrAbDpHS0YiLmnLzNcl1cJSstL4ba2KlJI3IkydhxA5xGLNlgeo1AoXsdAI1BMEgR9kb7Tv 8sWN3vIr6g4E0hMIUBClHckRuEd9vh6YjpnTJFa2R/uDhPuQdJUP4ef3f8vLDdDhtIi1gbbx1m5I mMXDKcwbJSkqAiBBIjl1M2/UHviCVQ0Q4tB/xArmQRtO08/r5Yzp6dXc8/P7UbfyHw9cOTmHLTtP UvKVSrbWFpB2IiVK7FHn/bywTUdmcW5JZUQkp7EbyP8Al/Pv6YVU6TAmLR9+8X3mMXX8WktphUgB IiRew6/Pc/vjVQ0igkGdikeU8nj4nCkp6UmJ9P8AKex/Pvg3Ysz2lOhg7Acg+vMJ+7v+ODJiiUgg FEKBgg8yBsDInnDVTsbA/L079f264YrrAVQJJi4F+Ynnz++xMqimNMDm

或者更长的时间我不知道。但它不会发布,因为它会插入过多的字符串(也许) 请帮助我如何将base64发布到服务器。谢谢

0 个答案:

没有答案