Using the Apache http commons code, the call:
CloseableHttpResponse response = httpclient.execute(target, httpget, localContext);
returns a response object which has a response.getStatusLine() method that returns a String that includes the response code. But no method to get the response code as an int.
How can I get the response code? Parsing the string strikes me as fragile as there might be a message with other numbers in it.
thanks - dave
From the StatusLine, you can call getStatusCode():
int statusCode = response.getStatusLine().getStatusCode();
I think this is what you are looking for:
response.getStatusLine().getStatusCode()
https://hc.apache.org/httpcomponents-client-4.5.x/httpclient/apidocs/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With