I'm connecting to URLs with Java (HttpURLConnection
).
I have noticed that in some cases, the response code is 3xx but the 'Location' header is empty.
How does a client browser know where to redirect after receiving this kind of HTTP response?
Thanks
Not all
3xx
replies can redirect automatically.300
provides multiple URLs in the response body, not in theLocation
header. The client/user has to decide which one to retrieve next.301
,302
,303
, and307
provide aLocation
only if the next URL is known. Otherwise, the client/user has to decide what to do next.304
is not a redirect. It is a response to a conditional GET, where the requested content has not changed since the requested criteria was last satisfied.305
always provides aLocation
to the required proxy to connect to.306
is not used anymore.If you look at the HTTP spec on some of the 3xx status codes, some of them only SHOULD provide a
Location
header.It doesn't. It's up to the client to handle what to do in that case.