我尝试过以下链接,但没有一个能帮助解决问题。
HttpPost returning error when using MultipartEntityBuilder in Android
以下是代码
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()));
错误
引起:java.lang.NoSuchFieldError:没有静态字段INSTANCE 输入Lorg / apache / http / message / BasicHeaderValueFormatter;在班上 Lorg /阿帕奇/ HTTP /消息/ BasicHeaderValueFormatter;或者它的 超类(声明 'org.apache.http.message.BasicHeaderValueFormatter'出现在 /system/framework/ext.jar)
我正在使用 httpcore-4.4.1 和 httpmime-4.4.1 库文件。
答案 0 :(得分:14)
答案 1 :(得分:0)
multipartBuilder.addPart(“images []”,fileBody); fileBody转换为byteArray,然后传递,因为数据以字节数组传输