本文是基于loopj (Asynchronous Http Client for Android) 的文件上传Demo
1、loopj 是基于 Apache's HttpClient 的异步http客户端
2、在项目中引用loopj ,用gradle方式
compile 'com.loopj.android:android-async-http:1.4.9'
3、权限配置
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
4、上传实现
public class MainActivity extends AppCompatActivity {
private static final String root = new String(Environment.getExternalStorageDirectory().getPath() + File.separator);
private String uploadURL = "http://192.168.155.6:8080/upload/UploadServlet";
private Button buttonUpload;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
su