简体   繁体   中英

How do I get the response code on an HttpClient request

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

StatusLine ,您可以调用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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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