/** * 异步get * * @param url get请求地址 * @param params get参数 * @param callBack 回调 */ @Override public void asyncGet(@NonNull String url, @NonNull Map<String, String> params, @NonNull final Callback callBack) { OkHttpUtils.get() .url(url) .params(params) .build() .execute(new StringCallback() { @Override public void onError(Call call, Response response, Exception e, int id) { callBack.onError(validateError(e, response)); } @Override public void onResponse(String response, int id) { callBack.onResponse(response); } }); }
/** * 异步post * * @param url post请求地址 * @param params post请求参数 * @param callBack 回调 */ @Override public void asyncPost(@NonNull String url, @NonNull Map<String, String> params, @NonNull final Callback callBack) { OkHttpUtils.post() .url(url) .params(params) .build() .execute(new StringCallback() { @Override public void onError(Call call, Response response, Exception e, int id) { callBack.onError(validateError(e, response)); } @Override public void onResponse(String response, int id) { callBack.onResponse(response); } }); }
private void getData() { String url = HttpContants.HOT_WARES + "?curPage=" + currPage + "&pageSize=" + pageSize; OkHttpUtils.get().url(url).addParams("type", "1") .build().execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { LogUtil.e(TAG, "response....." + e, false); } @Override public void onResponse(String response, int id) { LogUtil.e(TAG, "response....." + response, false); HotGoods hotGoods = mGson.fromJson(response, HotGoods.class); totalPage = hotGoods.getTotalPage(); currPage = hotGoods.getCurrentPage(); datas = hotGoods.getList(); showData(); } }); }
public void login(String email, String password, final HttpCallback<BaseBean> callback) { OkHttpUtils.post() .url(Url.URL_LOGIN) .addHeader("HTTP_X_REQUESTED_WITH", "XMLHttpRequest") .addParams("username", email) .addParams("password", password) .build() .execute(new JsonCallback<BaseBean>(BaseBean.class) { @Override public void onError(Call call, Exception e, int id) { e.printStackTrace(); callback.onFail(e.getMessage()); } @Override public void onResponse(BaseBean response, int id) { callback.onSuccess(response); } }); }
public void getToken( String mId, StringCallback callback, final UserListener userListener){ Log.i("lin","---*lin*---> getToken"); this.userListener = userListener; mUserId = mId; OkHttpUtils .post() .url("http://10.1.0.106:10000/api/generateTestToken") .addParams("appkey", "45") .addParams("app_secret","dc5cabddba054ffe894ba79c2910866c") .addParams("room","lalala") .addParams("user_id", mId) .build() .execute(callback); }
public void downCourse(final HttpCallback<DownCourseWrapper> callback) { OkHttpUtils.post() .url(Url.URL_DOWN_COURSE) .build() .execute(new JsonCallback<DownCourseWrapper>(DownCourseWrapper.class) { @Override public void onError(Call call, Exception e, int id) { e.printStackTrace(); callback.onFail(e.getMessage()); } @Override public void onResponse(DownCourseWrapper response, int id) { callback.onSuccess(response); LogUtil.e(this, "onResponse-->" + response.toString()); } }); }
private void getDanmu() { //下载demo然后设置 OkHttpUtils.get().url(TextUtils.concat("http://xingyuyou.com/Public/app/barragefile/","608","barrage.txt").toString()) .build() .execute(new FileCallBack(getApplication().getCacheDir().getAbsolutePath(), "barrage.txt")// { @Override public void onError(Call call, Exception e, int id) { } @Override public void onResponse(File response, int id) { if (!isDestory) { ((DanmakuVideoPlayer) danmakuVideoPlayer.getCurrentPlayer()).setDanmaKuStream(response); } } }); }
public void register(String email, String password, final HttpCallback<BaseBean> callback) { OkHttpUtils.post() .url(Url.URL_REGISTER) .addHeader("HTTP_X_REQUESTED_WITH", "XMLHttpRequest") .addParams("username", email) .addParams("password", password) .build() .execute(new JsonCallback<BaseBean>(BaseBean.class) { @Override public void onError(Call call, Exception e, int id) { e.printStackTrace(); callback.onFail(e.getMessage()); } @Override public void onResponse(BaseBean response, int id) { callback.onSuccess(response); } }); }
public void testUrl(String url, final HttpCallback<String> callback) { OkHttpUtils.get().url(url).build().execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { callback.onFail(e.getMessage()); e.printStackTrace(); } @Override public void onResponse(String response, int id) { callback.onSuccess(response); } }); }
public void userInfo(final HttpCallback<UserWrapper> callback) { OkHttpUtils.get() .url(Url.URL_USER_INFO) .build() .execute(new JsonCallback<UserWrapper>(UserWrapper.class) { @Override public void onError(Call call, Exception e, int id) { e.printStackTrace(); callback.onFail(e.getMessage()); } @Override public void onResponse(UserWrapper response, int id) { callback.onSuccess(response); } }); }
public void downShare(String shareUrl, final HttpCallback<DownCourseWrapper> callback) { OkHttpUtils.get() .url(shareUrl) .build() .execute(new JsonCallback<DownCourseWrapper>(DownCourseWrapper.class) { @Override public void onError(Call call, Exception e, int id) { e.printStackTrace(); callback.onFail(e.getMessage()); } @Override public void onResponse(DownCourseWrapper response, int id) { callback.onSuccess(response); LogUtil.e(this, "onResponse-->" + response.toString()); } }); }
/** * 下载网络数据 * @param url 网络请求地址 */ private void downloadData(String url) { OkHttpUtils.get().url(url) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { } @Override public void onResponse(String response, int id) { Log.i("===>response", response); parseJson(response); } }); }
public void download(String videoUrl, String path,String pathName, final OnDownLoadFileListener listener) { OkHttpUtils.get().url(videoUrl).build().execute(new FileCallBack(path,pathName) { @Override public void onBefore(Request request, int id) { listener.onStart(); } @Override public void inProgress(float progress, long total, int id) { listener.onProgress((int) progress); } @Override public void onError(Call call, Exception e, int id) { LogUtil.e("接受视频消息失败"); listener.onFailed(e); } @Override public void onResponse(File response, int id) { listener.onSuccess(response.getAbsolutePath()); LogUtil.e("接受到文件啦啦啦,文件路径为:" + response.getAbsolutePath()); } }); }