请求数据

搜索
  ApiService service = RetriftUtils.getinstance().getApiService(Api.url, ApiService.class);
        Call<GoodsBean> call = service.getgoods(s, 1, 20);
        call.enqueue(new Callback<GoodsBean>() {
            @Override
            public void onResponse(Call<GoodsBean> call, Response<GoodsBean> response) {
                GoodsBean bean = response.body();
                callBack.oncall(bean);
            }

            @Override
            public void onFailure(Call<GoodsBean> call, Throwable t) {

            }
        });


//搜索
    // http://172.17.8.100/small/commodity/v1/findCommodityByKeyword
    public static final String url="http://172.17.8.100/small/";


    // http://172.17.8.100/small/ commodity/v1/findCommodityDetailsById
    // commodityId
    // 商品详情

    // 购物车
    // http://172.17.8.100/ks/product/getCarts?uid=51
    public static final String gwcurl="http://172.17.8.100/ks/";

//搜索
// commodity/v1/findCommodityByKeyword
@GET("commodity/v1/findCommodityByKeyword")
Call<GoodsBean> getgoods(@Query("keyword")String keyword,@Query("page")int page,@Query("count")int count);


//商品详情
// commodity/v1/findCommodityDetailsById
@GET("commodity/v1/findCommodityDetailsById")
Call<GoodsXqBean> getxq(@Query("commodityId")int commodityId);

// product/getCarts?uid=51
@GET("product/getCarts?uid=51")
Call<GwcBean> gwc();

private static RetriftUtils retriftUtils;

private RetriftUtils() {

}

public static RetriftUtils getinstance() {
    if (retriftUtils == null) {
        synchronized (RetriftUtils.class) {
            if (retriftUtils == null) {
                return retriftUtils = new RetriftUtils();
            }
        }
    }
    return retriftUtils;
}

public static  Retrofit getRetrift(String url) {

    //请求头
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request().newBuilder()
                    .addHeader("userid", "")
                    .addHeader("sessionid", "")
                    .build();
            return chain.proceed(request);
        }
    });


    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(url)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    return retrofit;
}

public <T> T getApiService(String url, Class<T> service) {
    Retrofit retrofit = getRetrift(url);
    //通过java动态代理模式获取代理对象
    T t = retrofit.create(service);
    return t;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值