Is it possible to modify or add custom http header

2019-08-01 00:09发布

问题:

Does the HTTP protocol allow a 302 request header to be modified so some parameters can be set and passed to the url receiving the request?

回答1:

302 is a response code, not a request header. The client will resolve the redirect by doing a new request for the new URL, so your client may add whatever headers it want to that new request.

A server wanting some data be sent along to the new URL should do so by appending it to the URL as querystring variables, for example: http://example.com/new-url?variable=data.

If the redirect is happening within your own domain you may also set a cookie which the client may send to the new address. Cookies will only be sent inside the same domain, not if you are redirecting to somewhere else.