预期的 2-3 个参数,但得到 1.ts(2554) index.d.ts(2559, 23):未提供'body'参数



这是我的Angular服务方法,返回错误:

export class CartItemService {
constructor(private http:HttpClient) { }
addCartItem(pId:string, uId:string) {
return this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`);
}
}

这里是调用服务方法的组件方法:

addCartItem(pId:string, uId:string) {
this.cartItemService.addCartItem(pId,uId).subscribe({
next:(res) => alert('cart item added'),
error: (err) => alert('fail to add to cart')
})
}

服务方法中缺少什么?我真的没有什么可以传递的了。我只想把两个参数传递到后端,让Spring Boot来完成其余的POST。

必须为您的帖子请求提供一个正文,尽管该正文可能是空的。所以你可以这样做,例如:

this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`, {})

最新更新