MultipartEntityBuilder发送图片到铁路服务器 [英] MultipartEntityBuilder to send pictures to rail server

查看:1740
本文介绍了MultipartEntityBuilder发送图片到铁路服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送一个 MultipartEntityBuilder 来我的Rails的服务器。然而,当我尝试建立它崩溃,并给我的错误

I am trying to send a MultipartEntityBuilder to my Rails server. However when i try to build it it crashes and gives me the error

9月3日至25日:44:50.001 W / System.err的:java.util.concurrent.ExecutionException:java.lang.NoSuchMethodError:没有静态方法来创建(Ljava /朗/字符串; Lorg /阿帕奇/ HTTP /的NameValuePair;)Lorg /阿帕奇/ HTTP /实体/ ContentType的;类Lorg /阿帕奇/ HTTP /实体/ ContentType的;或它的超类(org.apache.http.entity.ContentType的声明

        HttpPost httpost = new HttpPost(url);
        MultipartEntityBuilder entity = new MultipartEntityBuilder.create();
        entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        for(int index=0; index < nameValuePairs.size(); index++) { 
            ContentBody cb;
            if(nameValuePairs.get(index).getName().equalsIgnoreCase("File")) { 
                File file = new File(nameValuePairs.get(index).getValue());
                FileBody isb = new FileBody(file);
                entity.addPart(nameValuePairs.get(index).getName(), isb);
            } else { 
                // Normal string data 

                cb =  new StringBody(nameValuePairs.get(index).getValue(),ContentType.TEXT_PLAIN);
                entity.addPart(nameValuePairs.get(index).getName(),cb); 
            } 
        } 
 return entity.build();

这是code我使用,我仍然在该MultipartEntity建设它会说错误得到错误。

This is the code i am using and i am still getting errors on the building of the the MultipartEntity it'll say the error.

推荐答案

尝试使用httpmime版本4.3.6

Try using httpmime version 4.3.6

我试着使用4.4或以上版本,但总是同样的问题。

I tried using 4.4+ but always the same problem.

这篇关于MultipartEntityBuilder发送图片到铁路服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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