在页面重定向上设置自定义请求标头 [英] Setting custom request header on a page redirect

查看:250
本文介绍了在页面重定向上设置自定义请求标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,可以将其称为server1:8080/amcd,该应用程序具有一个设置,当我在页面请求中传递自定义请求标头时,该用户可以自动登录.此自定义标头称为"REMOTE_USER".

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".

我的计划是在另一个Web应用程序上有另一个页面,我们称它为server2:8080/ssoRedirect/test.html服务器2上的该应用程序的行为就像一个过滤器,我将在其中传递URL参数,例如server2:8080 /ssoRedirect/test.html?UserName=user1,此页面将采用"user1"参数并重定向到server1:8080/amcd页面,同时在"REMOTE_USER"页面请求中注入"user1"值.

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?

我在看下面的一些简单JavaScript,但无法正常工作.

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

<script>

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();
    client.open("POST", "/log");
    client.setRequestHeader(remoteinput, userinput);

}
    window.location.href = "http://ephesoft.eastus2.cloudapp.azure.com:8080/dcma/";

</script>

当我为chrome和firefox使用Modify标头插件时,我能够使此工作正常进行.

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

未请求页面标题的图像

推荐答案

除非使用XMLHttpRequest发出异步请求,否则网页无法设置HTTP请求标头.在这种情况下,您不是在进行重定向,例如单击href.无需依赖自定义标头,而是根据您的后端使用以下任意一种:

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. 饼干
  2. 获取变量
  3. POST变量

这篇关于在页面重定向上设置自定义请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆