post请求,然后解析服务器返回的json请求
那里不对,大神指点一下。谢谢
public void onClick(View view) {
String username = usernameEdit.getText().toString();
String password = passwordEdit.getText().toString();
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new FormBody.Builder()
.add("username", username)
.add("password", password)
.build();
Request request = new Request.Builder()
.url("http://test.ourwechat.com/test/auth.php")
.post(requestBody)
.build();
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject();
String code = jsonObject.getString("code");
} catch (JSONException e) {
e.printStackTrace();
}
if (code == -1){
Toast.makeText(Login.this,"登录失败",Toast.LENGTH_SHORT).show();
}