如何获取状态代码或更好地了解是否已发送消息? 我已经这样做了,但当然它不起作用。
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! ");
}
感谢您的建议
答案 0 :(得分:0)
变化:
status == "201"
为:
status.equals("201")
答案 1 :(得分:0)
字符串比较,如上所述。
status.equals("201")
或者您可以使用:
response.getStatusLine().getStatusCode() != HttpStatus.SC_OK
所有状态here