Body of Http.DELETE request in Angular2

前端 未结 12 1942
旧巷少年郎
旧巷少年郎 2020-12-02 08:23

I\'m trying to talk to a somewhat RESTful API from an Angular 2 frontend.

To remove some item from a collection, I need to send some other data in addition to the re

12条回答
  •  有刺的猬
    2020-12-02 09:11

    The REST doesn't prevent body inclusion with DELETE request but it is better to use query string as it is most standarized (unless you need the data to be encrypted)

    I got it to work with angular 2 by doing following:

    let options:any = {}
    option.header = new Headers({
        'header_name':'value'
    });
    
    options.search = new URLSearchParams();
    options.search.set("query_string_key", "query_string_value");
    
    this.http.delete("/your/url", options).subscribe(...)
    

提交回复
热议问题