teocci / httpclientandroidlib

Automatically exported from code.google.com/p/httpclientandroidlib
Other
0 stars 0 forks source link

DefaultHttpClient() is depricated in the new build #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What should i use instead of DefaultHttpClient() in order to do a 
multipart/form request ? 

Below is my code for uploading a file:

    String upload_url = BASE_URL + UPLOAD_FILE;
         HttpClient httpclient = new DefaultHttpClient();
        HttpPost postRequest = new HttpPost(upload_url);
        MultipartEntityBuilder entity = MultipartEntityBuilder.create();

        try {
            // Set Data and Content-type header for the image
            FileBody fb = new FileBody(file, ContentType.MULTIPART_FORM_DATA);
            StringBody directoryIDString = new StringBody(directoryID + "",ContentType.TEXT_PLAIN);
            StringBody imageCreatedString = new StringBody(image_created_on
                    + "",ContentType.TEXT_PLAIN);

            Log.e("Upload File Response", image_created_on);

            entity.addPart("directory_id", directoryIDString);
            entity.addPart("created_on", imageCreatedString);
            entity.addPart("file", fb);
            postRequest.setEntity(entity.build());

            HttpResponse response = httpclient.execute(postRequest);
            // Read the response
            String jsonString = EntityUtils.toString(response.getEntity());
            Log.i("Upload File Response ", jsonString);
            return true;

        } catch (Exception e) {
            Log.e("Error in uploadFile", e.getMessage());
            return false;
        }

Original issue reported on code.google.com by sherazkh...@gmail.com on 28 Mar 2014 at 11:34

GoogleCodeExporter commented 8 years ago
maybe you can use HttpClient httpclient = HttpClientBuilder.create().build()

Original comment by dico...@gmail.com on 24 Apr 2014 at 8:00