Android network programming using httpclient and Multipartentitybuilder batch upload files and text simultaneously

Source: Internet
Author: User

/** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.