apache httpcomponents - Send text file to distant server in Android -
i trying send file android phone distant server. code used:
public void sendfile() { try { // httpclient httpclient client = new defaulthttpclient(); // post header httppost post = new httppost("http://example.com/get_data.php"); // add data multipartentitybuilder builder = multipartentitybuilder.create(); builder.setmode(httpmultipartmode.browser_compatible); file folder = this.mcontext.getfilesdir(); file file = new file(folder, "test.txt"); if (file.exists()) { log.d(tag, "file exists : " + folder.listfiles()[0].tostring()); } builder.addpart("file", new filebody(file)); builder.addbinarybody("file", file); httpentity entity = builder.build(); post.setentity(entity); httpresponse response = client.execute(post); httpentity httpentity = response.getentity(); log.v("result", entityutils.tostring(httpentity)); } catch (exception e) { e.printstacktrace(); } } this code should correct since found similar examples here , there. problem occurs when build multipartentitybuilder:
httpentity entity = builder.build(); i error:
caused by: java.lang.noclassdeffounderror: failed resolution of: lorg/apache/http/util/args; @ org.apache.http.entity.mime.content.abstractcontentbody.<init>(abstractcontentbody.java:48) @ org.apache.http.entity.mime.content.filebody.<init>(filebody.java:96) @ org.apache.http.entity.mime.multipartentitybuilder.addbinarybody(multipartentitybuilder.java:141) @ org.apache.http.entity.mime.multipartentitybuilder.addbinarybody(multipartentitybuilder.java:146) @ com.example.kevin.recordacceleration.accelerometer.sendfile(accelerometer.java:149)
the file i'm trying send in internal memory, , check existence: exists.
it not latest version because read on other topic version of httpmime , httpclient should work
your app missing commons-codec , commons-logging on httpcore , httpclient depends. httpmime depends on httpclient.

Comments
Post a Comment