这个问题可能是由于未正确设置请求头和数据传输格式而导致的。以下是一个可能的
const headers = new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded');
const payload = new URLSearchParams();
payload.set('param1', 'value1');
payload.set('param2', 'value2');
this.httpClient.post('/api/endpoint', payload.toString(), {headers});
@RequestMapping(value = "/api/endpoint", method = RequestMethod.POST)
public ResponseEntity myAPIEndpoint(@RequestParam("param1") String param1, @RequestParam("param2") String param2) {
// your code here
}
通过这种方式,您将能够在Angular中正确发送POST请求并在SpringBoot API中获取参数值。