OkHttp的post请求
Posted 白日梦游
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
}
}
});
以上是关于OkHttp的post请求的主要内容,如果未能解决你的问题,请参考以下文章
OkHttp 2.0 响应(POST 请求)正文字符串为空字符串