public void cancleFollow(String url) throws IOException { RequestBody formBody = new FormEncodingBuilder().add("accessToken", accessToken).build(); Request request = new Request.Builder().url(url).delete().build(); OkHttpUtil.enqueue( request, new Callback() { @Override public void onFailure(Request request, IOException e) { Message msg = new Message(); msg.what = 4; msg.obj = e.getMessage(); mHandler.sendMessage(msg); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { Message msg = new Message(); msg.what = 3; mHandler.sendMessage(msg); Log.e("videoInfoActivity", mlist.size() + ""); } } }); }
void followPost(String url) throws IOException { RequestBody formBody = new FormEncodingBuilder() .add("userId", userId) .add("toUserId", toUserId) .add("accessToken", accessToken) .build(); Request request = new Request.Builder().url(url).post(formBody).build(); OkHttpUtil.enqueue( request, new Callback() { @Override public void onFailure(Request request, IOException e) { request.body().toString(); Message msg = new Message(); msg.what = 4; msg.obj = e.getMessage(); mHandler.sendMessage(msg); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { Message msg = new Message(); msg.what = 2; mHandler.sendMessage(msg); } } }); }
void getUsers(String url) throws IOException { Request request = new Request.Builder().url(url).build(); OkHttpUtil.enqueue( request, new Callback() { @Override public void onFailure(Request request, IOException e) { Message msg = new Message(); msg.what = 4; msg.obj = e.getMessage(); mHandler.sendMessage(msg); } @Override public void onResponse(Response response) throws IOException { Gson gson = new Gson(); if (response.isSuccessful()) { Person person = gson.fromJson(response.body().charStream(), new TypeToken<Person>() {}.getType()); if (person.getResponseCode().equals("200")) { if (person.getUsers().size() > 0) { mlist = person.getUsers(); Message msg = new Message(); msg.what = 1; mHandler.sendMessage(msg); } else { Message msg = new Message(); msg.what = 6; mHandler.sendMessage(msg); Log.e("videoInfoActivity", "连cishu chakan ...................."); } } else if (person.getResponseCode().equals("500")) { Log.e("videoInfoActivity", "连接服务器失败"); } else { Message msg = new Message(); msg.what = 5; msg.obj = person.getResponseMsg(); mHandler.sendMessage(msg); } } } }); }