如何使用Angular中的delete方法在body中传递数据?

How can I use the delete method in Angular to pass data in body?

我创建了以下 AWS lambda 函数,目的是定义软删除和硬删除我的产品。

exports.handler = async (event) => { 
    const product = JSON.parse(event.body);
    let sql;
    let msg;
    let values;
   if (product.action == 'delete')  {
        sql = "UPDATE product_table SET isDeleted=1, deletedon=? WHERE product_id=?";
        msg = 'The product has been sucessfully deleted';
        values = new Date();
    } else if (product.action == 'restore') {
        sql = "UPDATE product_table SET isDeleted=0, deletedon=? WHERE product_id=?";
        msg = 'The product has been successfully restored';        
        values = null;
    }
    
    try {    
        const data = await new Promise((resolve, reject) => {
            connection.getConnection(function (err) {   
                if (err) {
                    reject(err);     
                }
            connection.query(sql, [values, product.product_id], function (err, result) {
                    if (err) {  
                        console.log("Error->" + err);     
                        reject(err);        
                    }         
                    resolve(result);  
                });     
            });  
        }); 
        
        return { 
            statusCode: 200,  
            body: JSON.stringify(msg)
        };     
    } catch (err) {    
        return {   
            statusCode: 400,   
            body: JSON.stringify(err.message) 
        };
    }
};

想法是使用 API 中的单个删除方法,并在 JSON 对象中传递 id 和 action 值,以便在删除和恢复之间切换。

我可以在 Postman 上使用它,但不能从我的 Angular 应用程序中使用。我像使用 POST 方法一样传递值 sam。你能帮我解决我遗漏的问题吗?

下面是angular代码:

deleteProductData(product_id:number,action:string) {
      const header: HttpHeaders = new HttpHeaders()
          .append('Content-Type', 'application/json; charset=UTF-8')
      const httpOptions = {
          headers: header,
          body:JSON.stringify({ "product_id": product_id,"action":action })
      };    
     return this.http.delete<any>(this.productGetUrl, httpOptions);
  }

发现问题。我的配置不正确。

我试图在 'body' 中发送 delete 方法的数据,不知道 delete 方法只支持 queryStringParameters 或 pathParameters。

我能够通过重构我的后端来解决这个问题,类似于我配置 GET 请求的方式。