Angular 8-自定义HTTP标头的Spring Boot服务器返回错误:MissingRequestHeaderException

问题描述 投票:0回答:1

我正在尝试将自定义http标头添加到我的GET请求中我正在为应用程序使用Angular 8和spring boot。我无法理解如何以正确的方式发送此标头,以及为什么服务器没有得到它。这是我的尝试:((客户)

const headers = new HttpHeaders().set("realityId", "0");

export class FileService {
constructor(private http: HttpClient) { }
getFileList(): Observable<any> {
return this.http.get(`${this.baseUrl}`,{headers});
}

以及我控制器中的相关服务器代码:

public HttpEntity<FlowersList> getFlowersFromFlowers(@RequestHeader String realityId, 
@RequestParam("mName") String mName)

无论我要做什么,我都会不断收到错误:

[org.springframework.web.bind.MissingRequestHeaderException: Missing request header 'realityId' for 
method parameter of type String]

我一直在尝试这样做:

 httpOptions = {
 headers: new HttpHeaders({ 'realityId': '0' })
  };

但是没什么,我一直在关注this tutorialthis one,并试图从此stuck overflow question.获得帮助

任何帮助将不胜感激

P.s我为角度2和4找到的任何解决方案都对我不起作用。

编辑:我也发现了this solution,尝试了完全相同的操作,并且仍然不断收到此错误。.我不明白我在做什么错]

angular spring-boot http-headers httprequest
1个回答
0
投票

尝试这样:

let headers = new HttpHeaders();
headers = headers.set("realityId", "0");

第一个标头的实例是不可变的。

© www.soinside.com 2019 - 2024. All rights reserved.