Forums Login/signup

Passing header parameters with the request

+Pie Number of slices to send: Send
Hi

I have the requirement of passing header parameters along the request(not as request parameters, value need to be send via header information).

I googled to find if there is any possibility to send header information using javascript, but in vain.
I also tried using servlet response.sendRedirect() like as shown below:

String redirect_uri = "https://localhost:8080/MyApp";
response.addHeader("ACT", "TEST");
response.sendRedirect(redirect_uri);

The request gets redirected but the header value do not get passed, as the browser makes a new request which do not contain the header information i put in the servlet. Kindly suggest me a way i can pass information to my application url via headers.

Thanks,
Sanjaykar
+Pie Number of slices to send: Send
From where to where are you trying to pass information? From the browser to the server? After a redirect? Then you'll have use parameters, since headers aren't preserved through a client-side redirect.
+Pie Number of slices to send: Send
Actually i want to make a client side redirect (i.e, when you click a hyperlink on the browser you will be redirected to a different url passing few header parameters along the request).

I tried to do this from javascript as well as servlet redirection. Both ways did not succeed me.
+Pie Number of slices to send: Send
If you use XmlHTTPRequest from within JavaScript then setting headers is possible. Not by following a link in the HTML page.

Why do you want to use headers instead of URL parameters?
+Pie Number of slices to send: Send
My client server expects few parameters only as part of the header and not in the request.

So do you want me to use XMLHttpRequest which is an ajax style of call, right? Is that possible to redirect to the url from the browser using XMLHttpRequest ?

Thanks.
+Pie Number of slices to send: Send
Why is the server expecting headers from the client if the client can't set those?

Is that possible to redirect to the url from the browser using XMLHttpRequest ?


No. Such a request is sent from JavaScript running in a web page. That was just an example of how to send headers. If this is a browser responding to clicks on links and such, then you need to use URL parameters and HTML forms to transfer data.

reply
reply
This thread has been viewed 6300 times.
Similar Threads
Passing Http headers to a different domain.
sending parameters from one servlet to another
Sent data to different Application servlet
forwarding request to some other server
response.redirect and jsp:forward
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 30, 2025 06:43:06.