Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

passing a body containing a json array of items for delete in angular

I have a REST API as below which is using the HTTP DELETE method. I have to pass this body in that HTTP DELETE method in Angular. Please help. I cannot change the structure of this body

{
"transactions": [
        {
"eventId": "21012200237172",
"productCode": "LC",
"id": "LC20110000090023"
        }
    ]
}
question from:https://stackoverflow.com/questions/65950492/passing-a-body-containing-a-json-array-of-items-for-delete-in-angular

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can pass body in httpdelete with options

let apiUrl = 'yourUrl';
let transactions = [{
    "eventId": "21012200237172",
    "productCode": "LC",
    "id": "LC20110000090023"
}];

const options = {
  headers: new HttpHeaders({
    'Content-Type': 'application/json',
  }),
  body: {
    transactions: transactions
  },
};

this.httpClient
  .delete(apiUrl, options)
  .subscribe((s) => {
    console.log(s);
  },err => {
    console.log(err);
  });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...