gpt4 book ai didi

android - Android 中 MultiPart 可编译方法的 NoClassDefFoundError

转载 作者:可可西里 更新时间:2023-11-01 16:52:27 26 4
gpt4 key购买 nike

我正在处理以下问题:当尝试通过 MultiPart 实体上传图像时,似乎 HttpClient/MIME 上的几个更新正在破解一切。我正在尝试以下代码,但它因 NoClassDefFoundError 而失败:

public static void executeMultipartPost(File image, ArrayList<Cookie> cookies, String myUrlToPost) {
try {
// my post instance
HttpPost httppost = new HttpPost(myUrlToPost);
// setting cookies for the connection session
if (cookies != null && cookies.size() > 0) {
String cookieString = "";
for (int i=0; i<cookies.size(); ++i) {
cookieString += cookies.get(i).getName()+"="+cookies.get(i).getValue()+";";
}
cookieString += "domain=" + BaseUrl + "; " + "path=/";
httppost.addHeader("Cookie", cookieString);
}
// creating the http client
HttpClient httpclient = new DefaultHttpClient();
// creating the multientity part [ERROR OCCURS IN THIS BELLOW LINE]
MultipartEntity multipartEntity = new MultipartEntity();
multipartEntity.addPart("photoupload", new FileBody(image));
httppost.setEntity(multipartEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
} catch (Exception e) {}
}

此方法完全可编译并使用 httpclient-4.0.1.jarhttpmime-4.2.jar libs,但同样,它在我的注释行上崩溃了。

我错过了什么吗?

最佳答案

好的,here你有 Multipart post 所需的库,所有功劳都归功于 Satya KomatineniDavid Maclean,Pro Android 3 和现在 4 的作者,我引用他们的书

To do multipart POST calls, you need to get three additional Apache open source projects: Apache Commons IO, Mime4j, and HttpMime. You can download these projects from the following web sites: Commons IO: http://commons.apache.org/io/ Mime4j: http://james.apache.org/mime4j/ HttpMime: http://hc.apache.org/downloads.cgi (inside of HttpClient)

关于android - Android 中 MultiPart 可编译方法的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10901143/

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