JsonObject object = new JsonObject(); JsonArray jsonArray = new JsonArray(); jsonArray.add("0x69987bfE7D7aC505ca65D312f8Ca11591E77c41d"); jsonArray.add("latest"); object.addProperty("jsonrpc","2.0"); object.addProperty("method","eth_getBalance"); object.add("params",jsonArray); object.addProperty("id",1); RequestBody body = RequestBody.create(JSON, object.toString()); HttpMethods.getInstance().getHttpService().getBlance(body) .compose(RxHelper.io_main()) .subscribeWith(new BaseSubscriber2<>());
@POST(MAIN_URL) Flowable<Object> getBlance(@Body RequestBody body);
public OkHttpClient getOkHttpClient2() { OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); OkHttpUtil.setHttpConfig(httpClientBuilder); if (BuildConfig.DEBUG) { //设置log拦截器 httpClientBuilder.addInterceptor(OkHttpUtil.getInterceptor(0)); } httpClientBuilder.authenticator(new Authenticator() { @Override public Request authenticate(Route route, okhttp3.Response response) throws IOException { if (responseCount(response) >= 3) { return null; } String credential = Credentials.basic("admin", "admin"); return response.request().newBuilder().header("Authorization", credential).build(); } }); return httpClientBuilder.build(); } public static int responseCount(okhttp3.Response response) { int result = 1; while ((response = response.priorResponse()) != null) { result++; } return result; }