Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultipartEntityBuilder to send pictures to rail server

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

03-25 09:44:50.001 W/System.err﹕ java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: No static method create(Ljava/lang/String;[Lorg/apache/http/NameValuePair;)Lorg/apache/http/entity/ContentType; in class Lorg/apache/http/entity/ContentType; or its super classes (declaration of '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();

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.

like image 353
Byrd Avatar asked Mar 25 '15 14:03

Byrd


1 Answers

Try using httpmime version 4.3.6

I tried using 4.4+ but always the same problem.

like image 53
Matheus Avatar answered Oct 29 '22 16:10

Matheus