我正在嘗試將產品添加到我的客人購物車中,將guest_id傳遞給網址中的guest_id以及正文中的listings_id。 這是方法:Etsy in Angular:將產品添加到客戶購物車
addToGuestCart(){
this.http.post(`https://openapi.etsy.com/v2/guests/${this.guest.guest_id}/carts?api_key=my-api-key`, this.product.listing_id)
.first()
.subscribe(()=>this.getGuest());
}
我得到這個CORS錯誤:
HTTP POST體的XMLHttpRequest cannot load https://openapi.etsy.com/v2/guests/akye30nuit6ua/carts?api_key=my-api-key . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:4200 ' is therefore not allowed access. The response had HTTP status code 500.
我無法通過url發送值,因爲http.post需要主體參數。在主體中使用{listing_id:this.product.listing_id}會返回與之前相同的'Access-Control-Allow-Origin'錯誤,但是現在我得到400的HTTP狀態代碼而不是500。 – cerealex