页面重新加载后表示无法保存标题

时间:2018-07-19 12:52:50

标签: javascript node.js

成功登录后,我正在使用此方法设置授权标头

router.post('/attempt', function (req, res, next) {
.....
.....
req.headers.authorization = 'JWT ' + token;
console.trace(req.headers.authorization)

,调试后我可以看到它设置正确。因此,我尝试在相同的路由上调试相同的标头,但要先设置

router.post('/attempt', function (req, res, next) {
    console.error(req.headers.authorization)

但是它是undefined。怎么可能?设置好了,页面重新加载后清除了吗?

1 个答案:

答案 0 :(得分:0)

如果您想将标题发送到浏览器,请像

一样使用import java.util.Arrays; import java.util.Scanner; public class String2intArray { public static void main(String[] args) { System.out.println(Arrays.toString(str2ia("6,8 ,9 , 10"))); System.out.println(Arrays.toString(str2ia("1002"))); System.out.println(Arrays.toString(str2ia(""))); System.out.println(Arrays.toString(str2ia(", 2"))); System.out.println(Arrays.toString(str2ia("one,two"))); System.out.println(Arrays.toString((str2ia("1,,2")))); System.out.println(Arrays.toString(str2ia("1 , 2 ,"))); } public static int[] str2ia(String s) { int arraylengt = 0; int arrayindex = 0; Scanner scan = new Scanner(s).useDelimiter(" *, *"); if(s.length() == 0) { int[] emptyArray = {}; System.out.print("empty array "); return emptyArray; } while (scan.hasNext()) { if (scan.hasNextInt()) { int nextInt = scan.nextInt(); arraylengt ++; } else { // discard next token scan.next(); } } int[] intArray = new int[arraylengt]; Scanner scan2 = new Scanner(s).useDelimiter(" *, *"); try { while (scan2.hasNext()) { if (scan2.hasNextInt()) { intArray[arrayindex] = scan2.nextInt(); arrayindex++; } else { // discard next token throw new IllegalArgumentException("Bad input"); } } } catch (IllegalArgumentException e) { System.out.print("Bad input"); int[] emptyArray = {}; return emptyArray; } return intArray; } }
res.set();

但是,如果您想从请求中获取标头,请使用res.set('authorization', 'JWT ' + token); 对象,如

req.headers