0

How to get the status code or something better to know if an message was sent? I already do this, but off course it don't work.

            httppost.setEntity(new StringEntity(message.toString()));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            String status = response.getStatusLine().toString();

            Log.d(CLASS_TAG + "showOnScreenMessage", "Message sent! ");
            Log.d(CLASS_TAG + "showOnScreenMessage", "Status : " + status );

            // if response == 201 , the message has be received, Set True to acknowledgment_message 
            if ( status == "201"){
                Log.d(CLASS_TAG + "showOnScreenMessage", "Message received! ");


            }else{
                // Do nothing already false
                Log.d(CLASS_TAG + "showOnScreenMessage", "Message not received! ");
            }

Thanks for your suggestions

Ben
  • 501
  • 6
  • 20
  • `if ( status == "201"){` doesn't seem correct. Take a look at [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Pshemo Mar 18 '14 at 17:09

2 Answers2

0

Change:

status == "201"

to:

status.equals("201")
crazylpfan
  • 1,038
  • 7
  • 9
0

String compare as it's say above.

status.equals("201")

Or you can use :

response.getStatusLine().getStatusCode() != HttpStatus.SC_OK

All status here

Neige
  • 2,770
  • 2
  • 15
  • 21