您的位置:首页 > 理论基础 > 计算机网络

OkHttp Post请求方式

2016-07-01 08:01 429 查看
String path = "https://ic.snssdk.com/user/mobile/login/v2/";
OkHttpClient httpClient = new OkHttpClient();
FormBody body = new FormBody.Builder()
.add("mobile", et_phone.getText().toString().trim())
.add("password", et_pwd.getText().toString().trim())
.build();
Request request = new Request.Builder()
.url(path)
.post(body)
.build();
Call call = httpClient.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()) {

/*解析*/
Gson gson = new Gson();
LoginBean loginBean = gson.fromJson(response.body().string(), LoginBean.class);
<span style="white-space:pre">		</span>}

}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: