简体   繁体   English

HTTP POST请求的JAVA GET响应

[英]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")

String compare as it's say above. 字符串比较,如上所述。

status.equals("201")

Or you can use : 或者您可以使用:

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

All status here 这里的所有状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM