对于HTTP POST请求JAVA GET响应 [英] JAVA GET response for HTTP POST Request
本文介绍了对于HTTP POST请求JAVA GET响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让状态code或更好的东西知道是否发送了消息?
我已经做到这一点,但脱离当然它不工作。
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! ");
}
感谢您的建议
推荐答案
字符串比较,因为它是上面说的。
String compare as it's say above.
status.equals("201")
或者你可以使用:
Or you can use :
response.getStatusLine().getStatusCode() != HttpStatus.SC_OK
所有的状态这里
这篇关于对于HTTP POST请求JAVA GET响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文