android Observable api请求参数设置注解问题

android Observable api请求参数设置注解问题

2018-10-29 20:05:24.919 11786-11786/xxx E/wxh: getQuote=USD getBase=ETH
2018-10-29 20:05:24.927 11786-11786/xxx E/ProgressObserver____: onSubscribe:
2018-10-29 20:05:24.933 11786-11841/xxx D/OkHttp: --> POST http://192.168.2.xx:xxxx/api/v1/favorites/%7Bpair%7D

LogUtil.e("wxh", "getQuote=" + data.getQuote() + " getBase=" + data.getBase());
subscribe(coinSearchActivity,Api.getApiService().addFavorites(data.getQuote() + data.getBase()),
new ObserverResponseListener<Object>() {
打印出来是有值的,为什么传到接口那是没有替换掉?

@FormUrlEncoded
@POST("api/v1/favorites/{pair}")
Observable<Object> addFavorites(@Field("pair") String pair);

如果直接把@Field改成@Path则直接崩溃了
问题:没有表单字段的不能用@FormUrlEncoded、@Field注解,URL里面的参数的使用@Path注解,@FormUrlEncoded和@Path注解不能同时使用
//添加收藏
@POST("api/v1/favorites/{pair}")
Observable<Object> addFavorites(@Path("pair") String pair);

public void addFavorites(CoinListInfo data,BaseBindingAdapter mAdapter){
       LogUtil.e("wxh", "getQuote=" + data.getQuote() + " getBase=" + data.getBase());
subscribe(coinSearchActivity,Api.getApiService().addFavorites(data.getQuote() + data.getBase()),
                new ObserverResponseListener<Object>() {
            @Override
            public void onNext(Object o) {
                //ToastUtil.showLongToast("add favorites on next");
                //if exits set true or set false
                data.isFavorite.set(Boolean.TRUE);
                mAdapter.notifyDataSetChanged();
            }

            @Override
            public void onError(Throwable e) {
                ToastUtil.showLongToast("add favorites on error");
            }
        }, coinSearchActivity.bindToLifecycle());

   }

 

posted @ 2018-10-29 21:37  大自然的流风  阅读(1989)  评论(0编辑  收藏  举报