MyApi类 写api
public class MyApi { public static final String denglu = "https://www.zhaoapi.cn/";
}
写GET
public interface MyService { @GET("user/login") Observable<Bean_d> getdl(@Query("mobile") String a, @Query("password") String b); }
把传过来的数据进行添加
public void getdl(String denglu, String sj, String mima) { HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.i("xxxx",message); } }); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(httpLoggingInterceptor) .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(denglu) .client(okHttpClient) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); MyService myService = retrofit.create(MyService.class); Observable<Bean_d> getdl = myService.getdl(sj, mima); getdl.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<Bean_d>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { Log.i("zz","1111111"); } @Override public void onNext(Bean_d bean_d) { model_dl_I1.success(bean_d); Log.i("zz",bean_d.toString()); } });