我只是为了测试目的而硬编码JWT,但是我的角应用程序中的这两行让我遇到以下错误:
代码:
this.localStorageService.set("jwt", "Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImltYy1hcGkifQ.eyJpc3MiOiJWVFAgQVBJIiwiaWF0IjoxNDYzNDI0Njk2LLJqdGkiOiJ6ckEyN2lOcGhsUi1Wdkl1VGZPWFNRIiwib3JnYW5pemF0aW9uSWQiOiIxIiwidXNlck5hbWUiOiJ0ZXN0VXNlciIsInVzZXJJZCI6IjEifQ.xWe_TK6F9t6hCMm7KB8WNy5HmUkiWJRIRZg0POjMuzyL8VjRSe9aWREqdHWvu6nqOv8Sfm5RsC7lrB3inqjE4Tim0Njy52Wxa9FuYllz11qmce6QSquti2hfHu6Trfzosiwl54y8cBfgm2VlLWIb2ukinJhcxCr8-rJzfK4hM9R-cgI-_Yd459JDmNj0HeJ-UlP9fIiCX71YZGEVag8Nqg9bdsSgTqmJQ3667W_p_vyPK1P1whvhFBGUydXjZRk_W01pgr2AON3N_-EmzJAo7t1J0Rll0BxB4aQXTNdX1vmhoNllqcr81ZxC-5k77-Eci-4gaWY9fLG7ADR872jKog");
this.$http.defaults.headers.common.Authorization = String(this.localStorageService.get("jwt"));
错误:
Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImltYy1hcGkifQ.eyJpc3MiOiJSVFAgQVBJIiwiaWF0IjoxNDYzNDI0Njk2LCJqdGkiOiJ6ckEyN2lOcGhsUi1Wdkl1VGZPWFNRIiwib3JnYW5pemF0aW9uSWQiOiIxIiwidXNlck5hbWUiOiJ0ZXN0VXNlciIsInVzZXJJZCI6IjEifQ.xWe_TK6F9t6hCMm7KB8WNy5HmUkiWJRIRZg0POjMuzyL8VjRSe9aWREqdHWvu6nqOv8Sfm5RsC7lrB3inqjE4Tim0Njy52Wxa9FuYllz11qmce6QSquti2hfHu6Trfzosiwl54y8cBfgm2VlLWIb2ukinJhcxCr8-rJzfK4hM9R-cgI-_Yd459JDmNj0GeJ-UlP9fIiCX71YZGEVag8Nqg9bCsSgTqmJQ3667W_p_vyPK1P1whvhFBGUydXjZRk_W01pgr2AON3N_-EmzJAo7t1J0Rll0BxB4aQXTNdX1vmhoNllqcr81ZxC-5k77-Eci-4gaWY9fLG7ADR872jKog' is not a valid HTTP header field value.
不是有效的HTTP标头字段值。我试过没有String()和angular.fromJson无济于事。 有人碰到这个/有什么建议吗?
提前致谢 -
答案 0 :(得分:1)
我们遇到了这个问题。修复是因为我们在字符串中有一个坏字符...更具体地说是一个回车符。
有关详细信息,请参阅HTTP 1.1规范(section 2.2和section 4.2)。
简要地查看你的标题值,我找不到任何非法字符,但这就是我要开始寻找的地方。