为了账号安全,请及时绑定邮箱和手机立即绑定

okhttp发送post返回的response.body().string()用equals值总是false,日志打印的字符串明明一样。

okhttp发送post返回的response.body().string()用equals值总是false,日志打印的字符串明明一样。

慕姐5506514 2017-11-20 23:55:05
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 回答
  • 0 关注
  • 2391 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信