Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing header parameters with the request

 
Sanjaykar Gurram
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Moores
Bartender
Posts: 2677
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sanjaykar Gurram
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Moores
Bartender
Posts: 2677
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sanjaykar Gurram
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Moores
Bartender
Posts: 2677
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic