将HTTPURLConnection与MultiPartEntityBuilder一起使用

时间:2016-02-10 10:21:29

标签: java android multipartentity

我正在使用以下代码段,

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();
        }

MultipartEntityBuilder中,没有名为writeTo(BufferedOutputStream bos)的方法,那么我应该使用哪种方法来使其工作?

注:

MultipartEntity is deprecated now from Android api-level 23 and above.

1 个答案:

答案 0 :(得分:0)

您必须如此构建localhost:3000

HttpEntity