这是返回错误的角服务方法:
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完成其余的POST工作。
发布于 2022-09-28 10:39:29
你必须为你的帖子请求提供一个身体,尽管那个身体可能是空的。因此,您可以这样做,例如:
this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`, {})https://stackoverflow.com/questions/73879591
复制相似问题