安卓 retrofit @body用法

Api


    @POST("接口")
    Observable<PullBean> pull(@Body RequestBody body);
    

presenter


    public void pull(String json){
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        Observable<PullBean> pull = okHttp.api.pull(requestBody);
        pull.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<PullBean>() {
                    @Override
                    public void accept(PullBean pullBean) throws Exception {
                        if (getView() !=null){
                            getView().onSuccess(pullBean);
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().onError(throwable.toString());
                    }
                });
    }
    

界面请求接口


                HashMap<String, String> map = new HashMap<String, String>();
                map.put("ID" , "");
                map.put("type" , "");
                map.put("userID" , "");

                gson = new Gson();
                pull = gson.toJson(map);
                presenter.pull(pull);
                

你可能感兴趣的:(安卓 retrofit @body用法)