getting incorrect error even if the condition is fulfilled
Posted
by
Tapan Desai
on Stack Overflow
See other posts from Stack Overflow
or by Tapan Desai
Published on 2012-10-24T16:57:53Z
Indexed on
2012/10/24
17:00 UTC
Read the original article
Hit count: 331
I am trying to show the message based on the text shown on webpage after a particular action. If the webpage contains text MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY, I want to print Message sent successfully on the screen otherwise MESSAGE SENDING FAILED. Everything is working fine but for one thing.
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();
The problem is that even if the webpage contains the text MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY, the condition always goes into ELSE
part and show MESSAGE SENDING FAILED but thats not true because the message has been sent and i see the MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY on the webpage.
Can anyone tell me where am i going wrong?
© Stack Overflow or respective owner