Setting custom request header on a page redirect

I have a web application lets call it server1:8080/amcd this application has a setting in it that allows a user to be auto logged in when i pass in a custom request header in the page request. This custom header is called "REMOTE_USER".

My plan is to have another page on another web application, lets call it server2:8080/ssoRedirect/test.html this app on server 2 is acting like a filter where i will pass in a URL parameter such as server2:8080/ssoRedirect/test.html?UserName=user1 this page will take the "user1" parameter and redirect to server1:8080/amcd page while injecting the "user1" value in the "REMOTE_USER" page request.

Any advice in how to I might accomplish this?

I was looking at some simple javascript like below but could not get it to work.


var url = "http://localhost:8080/index.html?userName=user1"; // or window.location.href for current url
var usernameParam = /userName=([^&]+)/.exec(url)[1]; 
var result = usernameParam ? usernameParam : 'myDefaultValue';

 function customHeader(remoteinput, userinput) {
    var client = new XMLHttpRequest();"POST", "/log");
    client.setRequestHeader(remoteinput, userinput);

    window.location.href = "";


I am able to make this work when I use the Modify header plugin for chrome and firefox.

Image of not request page header



A web page can not set HTTP request headers unless you are making an async request using XMLHttpRequest. In this case you are not, you are doing a redirect, like clicking on an href. Instead of relying on custom headers, depending on your backend use any one of these:

  1. Cookies
  2. GET variables
  3. POST variables


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.