/** by Keinta in China sz email: [Email protected] 2016.10.18
CN: This jar package has integrated Android HTTP network request package, also encapsulates the Multipartentitybuilder file and text upload simultaneously, to achieve backward compatibility
all you need to do is add these two packages to enable Android's multi-type network transmission.
Please add the packages:
Compile files (' Libs/org.apache.http.legacy.jar ')
Compile files (' Libs/httpmime-4.3.5.jar ')
Compile files (' Libs/android_httpcore_4.3.2.jar ')//https://pan.baidu.com/s/1i5mEO53
Inside The JAR package has integrated the Android HTTP Request Packet Network, also encapsulates the upload Multiparte Ntitybuilder file with the text at the same time, achieve backward compatibility
/** Example
* @param context
* @param url
* @param filekey
* @param params
* @param file
* @return
*/
Public String Postmutil (context context, string URL, String filekey, Final treemap<string, string> params, F ile file) {
//* * * * * * omitted
//image Attaching
Multipartentitybuilder multipartentity = Multipartentitybuilder.create ();
if (file = null && file.exists ()) {
multipartentity.addbinarybody (filekey, file, Contenttype.multipart_form_data, File.getname ());
}
//json String Attaching
for (map.entry<string, string> entry:params.entrySet ()) {
Multipartentity.addpart (Entry.getkey (), New Stringbody (Entry.getvalue ()));
}
httppost.setentity (Multipartentity.build ());
//****** omit ******
}
Compile files (' Libs/android_httpcore_4.3.2.jar ')//https://pan.baidu.com/s/1i5mEO53 package has been uploaded to the Baidu cloud can be downloaded directly with
This article from the "Soul Catcher" blog, reproduced please contact the author!
Android network programming using httpclient and Multipartentitybuilder batch upload files and text simultaneously