4 ms·
Why should you do this in Java: httpConn.getResponseCode() / 100 == 2 instead of: httpConn.getResponseCode() == 200
by dulvui 5y ago
Why should you do this in Java:
httpConn.getResponseCode() / 100 == 2
instead of:
httpConn.getResponseCode() == 200
- 4khilles 5y ago204 satisfies the first check but not the second.
- willcipriano 5y agoIf you intend to do anything with the response you'd probably handle 204 differently otherwise you'll get the world famous null pointer.
- detaro 5y agoI guess so it accepts all 2xx codes and not just 200?
- dulvui 5y agoOh now I understand: its to match all 200 HTTP codes like 201, 202, 203 etc.
- dragonwriter 5y agoBecause all 2xx responses are success; for simple (not Range or other special request scenarios) GET/HEAD it probably matters less in practice than for PUT/POST/DELETE, but 203 and 205 (and 204 for an existing but empty resource) are still possibilities.
- deleted 5y ago[deleted]