简体   繁体   中英

How to fetch the exact status code of the response using JSoup or HttpConnection?

Whenever I try to get the status code of a particular URL, both JSoup and HttpConnection always returns 200 even if there is a 301/302 redirect for the request URL. Did anyone else face a similar issue and what should be the workaround to get the status code of the first request?

The general strategy if you want to see redirection status codes is to turn off automatic redirect following. If you then want to follow the redirects, you can do it yourself ... by hand ... after making a note of the status code.

The details will depend on what you are using; eg HttpUrlConnection, Apache HttpClient v3, Apache HttpClient v4, or something else.

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