private void sentRequestWithOkHttpToLogin() { new Thread(new Runnable() { @Override public void run() { try { OkHttpClient client=new OkHttpClient(); RequestBody requestBody=new FormBody.Builder() .add("username",username) .add("password",password) .build(); Request request=new Request.Builder() .url(Login_url) .post(requestBody) .build(); Response response= client.newCall(request).execute(); responseData=response.body().string(); responseData=responseData.toString(); runOnUiThread(new Runnable() { @Override public void run() { if(responseData.equals("success")) { Log.d("user12",responseData); Toast.makeText(LoginActivity.this,"登录成功",Toast.LENGTH_SHORT).show(); UserFragment.login.setText(username); }else if(responseData.equals("fail")) { Log.d("user12",responseData); Toast.makeText(LoginActivity.this,"用户名密码不存在",Toast.LENGTH_SHORT).show(); } } }); } catch (IOException e) { e.printStackTrace(); } } }).start();}
添加回答
举报
0/150
提交
取消