为什么response.body().string()的值用equals与字符串对比总是返回false?
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();
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();
}