第一步:添加第三方依赖库
api 'com.lzy.net:okgo:3.0.4'
第二步:权限设置
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
第三步:Application中全局配置
@Override public void onCreate() { super.onCreate(); mContent = getApplicationContext(); OkGo.getInstance().init(this); }
POST请求
OkGo.<String>post(url) .tag(this) .params("key", "value") .params("key", "value") .isMultipart(true) .execute(new StringCallback() { @Override public void onSuccess(Response<String> response) { String bodyData = response.body(); GmBean data = new Gson().fromJson(bodyData, GmBean.class); } @Override public void one rror(Response<String> response) { super.onError(response); } });
姐妹们还是看原文章吧,我觉得他写的好好~~~ 原文章点这里