OkHttp的post请求

OkHttpClient client = new OkHttpClient();
FormBody body = new FormBody.Builder()
.add("mobile",mNumber)
.add("type","1").build();
final Request request = new Request.Builder()
.url(mPath)
.post(body).build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {

}

@Override
public void onResponse(Call call, Response response) throws IOException {
  if (response.isSuccessful()){
    String d = response.body().string();
    Gson gson = new Gson();
    RegisterData data = gson.fromJson(d, RegisterData.class);
    Message msg = Message.obtain();
    msg.obj = data;
    handler.sendMessage(msg);
  }
}
});

posted on 2016-07-01 08:01  白日梦游  阅读(2617)  评论(0)    收藏  举报

导航