我正在尝试根据特定操作后网页上显示的文字显示消息。如果网页包含 MESSAGE已成功提交的文字,我想打印在屏幕上成功发送的消息,否则MESSAGE SENDING FAILED。一切都运转良好,但有一件事。
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(sendConnection.getOutputStream()), true);
printWriter.print(sendContent);
printWriter.flush();
printWriter.close();
//Reading the returned web page to analyse whether the operation was sucessfull
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(sendConnection.getInputStream()));
StringBuilder SendResult = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
SendResult.append(line);
}
if (SendResult.toString().contains("MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY")) {
System.out.println("Message sent to " + phoneNumber + " successfully.");
} else {
System.err.println("Message could not send to " + phoneNumber + ". Also check login credentials");
}
bufferedReader.close();
问题是,即使网页包含 MESSAGE已成功提交的文字,条件也始终进入ELSE
部分并显示MESSAGE SENDING FAILED但这不是真的,因为该消息已被发送,我在网页上看到 MESSAGE已成功提交。
谁能告诉我哪里出错?
答案 0 :(得分:0)
试试这个:
if (SendResult.toString().trim().contains("MESSAGEHASBEENSUBMITTEDSUCCESSFULLY"))