【发布时间】:2020-03-19 14:46:35
【问题描述】:
我有一个小问题。当我使用 Postman 向我的 api 发送请求时,它可以工作,但是当我发送带有角度的东西时,他不喜欢。
邮递员:the request
春节快乐:
@GetMapping("/searchs")
@CrossOrigin(origins = "http://localhost:4200")
public Collection<SearchFeedDTO> getFeed ( @RequestBody String data){
System.out.println(data);
System.out.println("I'm here");
return null;
}
角度代码:
// data = {test:"hello"};
getFeed(data):Observable<boolean>{
return this.http.get<Answer>(`${this.baseUrl}api/searchs/`,data).pipe(
map(res=>true),
catchError(err=>{
console.error(err);
return of (false);
})
);
}
悲伤的 Spring 响应:“缺少所需的请求正文”
当我尝试这个时,Angular 并不高兴。
return this.http.get<Answer>(`${this.baseUrl}api/searchs/`,{test:"test"}).pipe(
=> 错误“没有与此调用匹配的重载”。
有什么想法吗?
非常感谢!
【问题讨论】:
-
HttpClient 不支持在 GET 请求中发送数据。您需要将方法更改为 POST 或在查询参数中发送数据。
标签: angular spring-boot