实体在 MultiPartEntityBuilder 中返回错误 [英] Entity returns error in MultiPartEntityBuilder

查看:36
本文介绍了实体在 MultiPartEntityBuilder 中返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下链接,但没有一个有助于解决问题.

I've tried following links but none of them helped to solve the issue.

在Android中使用MultipartEntityBuilder时HttpPost返回错误

https://stackoverflow.com/a/22803149/1226882

这是代码

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(Utility.AddProductWS);

MultipartEntityBuilder multipartBuilder = MultipartEntityBuilder.create();

/* example for setting a HttpMultipartMode */
multipartBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

for (int i = 0; i < photos.size(); i++) {

    multipartBuilder.addBinaryBody("images[]", newFile(photos.get(i).getImagePath());
}

multipartBuilder.addTextBody("username", username.toString());
multipartBuilder.addTextBody("accept_best_offer", String.valueOf(acceptOffer.isChecked() ? 1 : 0));
multipartBuilder.addTextBody("accept_trade", String.valueOf(acceptTrade.isChecked() ? 1 : 0));
multipartBuilder.addTextBody("product_price", etProductPrice.getText().toString());
multipartBuilder.addTextBody("product_description", etProductDescription.getText().toString());

HttpEntity httpEntity = multipartBuilder.build();
httpPost.setEntity(httpEntity);  // Error line
HttpResponse response = httpClient.execute(httpPost);
Utility.showLog(TAG, EntityUtils.toString(response.getEntity()));

错误

Caused by: java.lang.NoSuchFieldError: No static field INSTANCE of输入 Lorg/apache/http/message/BasicHeaderValueFormatter;在班上Lorg/apache/http/message/BasicHeaderValueFormatter;或其超类(声明'org.apache.http.message.BasicHeaderValueFormatter' 出现在/system/framework/ext.jar)

Caused by: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicHeaderValueFormatter; in class Lorg/apache/http/message/BasicHeaderValueFormatter; or its superclasses (declaration of 'org.apache.http.message.BasicHeaderValueFormatter' appears in /system/framework/ext.jar)

我正在使用 httpcore-4.4.1httpmime-4.4.1 库文件.

I am using httpcore-4.4.1 and httpmime-4.4.1 library files.

推荐答案

我终于解决了.

这是一个库问题,它适用于 4.3.1 版本.

这是下载库文件的链接

这篇关于实体在 MultiPartEntityBuilder 中返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆