0

我正在尝试根据特定操作后网页上显示的文本显示消息。如果网页包含文本MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY,我想在屏幕上打印 Message sent successfully 否则 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 HAS BEEN SUBMITTED SUCCESSFULLY,条件总是ELSE部分显示 MESSAGE SENDING FAILED 但这不是真的,因为消息已经发送并且我在网页上看到消息已成功提交.

谁能告诉我我哪里出错了?

4

1 回答 1

0

试试这个:

if (SendResult.toString().trim().contains("MESSAGEHASBEENSUBMITTEDSUCCESSFULLY")) 
于 2012-10-24T17:33:34.693 回答