1

I am using following code snippet,

URL url = new URL("http://www.android.com/");
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

        urlConnection.setDoOutput(true);
        urlConnection.setRequestMethod("POST");


        MultipartEntityBuilder reqEntity =  MultipartEntityBuilder.create();
        urlConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=");
        BufferedOutputStream bos = new BufferedOutputStream(urlConnection.getOutputStream());
        try {
          //  reqEntity.writeTo(bos); which method shall I use instead of writeTo();
         } finally {
            bos.close();
            bos.flush();
        }

In MultipartEntityBuilder, there is no method called, writeTo(BufferedOutputStream bos), So instead of that which method shall I used to make it work?

NOTE:

MultipartEntity is deprecated now from Android api-level 23 and above.
Rohit
  • 2,646
  • 6
  • 27
  • 52
  • This post may help you : [Past question](http://stackoverflow.com/questions/26210679/post-files-to-server-from-android-multipartentitybuilder-http) – Nikolay Tomitov Feb 10 '16 at 10:29
  • @NikolayTomitov: thnx for post but `HTTPPost` is deprecated in Android-api lvl 23, thats why we are trying with `HTTPURLConnection` and we are not able to find the method. – Rohit Feb 10 '16 at 10:32

1 Answers1

0

You have to build the HttpEntity so

ReqEntity.build().writeTo(<OutputStream>)

Alex Filatov
  • 2,232
  • 3
  • 32
  • 39