gpt4 book ai didi

java - 将 HTTPURLConnection 与 MultiPartEntityBuilder 结合使用

转载 作者:太空宇宙 更新时间:2023-11-04 12:57:00 25 4
gpt4 key购买 nike

我正在使用以下代码 fragment ,

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.

最佳答案

您必须构建 HttpEntity所以

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

关于java - 将 HTTPURLConnection 与 MultiPartEntityBuilder 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35312465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com