안드로이드 retrofit @body 사용법

8553 단어
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);
                

좋은 웹페이지 즐겨찾기