我在Java上有后端,在Angular 5上有前端。所以我在使用HttpClient时遇到了问题。当我发送带有令牌的帖子请求时,例如:
let headers = new HttpHeaders().set('Authorization', token);
this.http.post(url, data, {headers: headers})
.map((response: Response) => response.json());
我一直有 - 401错误(未经授权),但当我通过curl发送此请求时:
curl -s -X POST --header 'Authorization: sometoken' -d '{"text":
"somedata"}' 'http://someurl'
一切都好!可能有人遇到同样的问题吗?
NEW!也许它可以帮助,在Chromium的网络部分,我看到有关此请求的下一个信息:
Request headers:
Accept: / Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
Access-Control-Request-Headers: authorization,content-type
Access-Control-Request-Method: POST Connection: keep-alive