[英]JAVA GET response for HTTP POST Request
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 谢谢你的建议
Change: 更改:
status == "201"
to: 至:
status.equals("201")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.