美文网首页Angular
HttpClient delete 请求添加 body - an

HttpClient delete 请求添加 body - an

作者: survivorsfyh | 来源:发表于2021-01-08 11:00 被阅读0次

    使用 angular 中 HttpClient 的 delete 方法时发现官方提供的方法中没有直接传 body 的方式;
    经过尝试可以通过 options 的方式将 body 包在该对象其中后发起请求,具体 code 如下:

    import {HttpClient, HttpHeaders} from '@angular/common/http';
    
    deleteExaminationTask(caId: string, token: string, ids: any) {
        const options = {    
            headers: new HttpHeaders({
                'Content-Type': 'application/json',
                caid: caId,
                token: token,
            }),
            body: ids
        };
        return this.http.delete(`/api/exam/task`, options).pipe(catchError(err => err));
    }
    

    以上便是此次分享的全部内容,希望能对大家有所帮助!

    相关文章

      网友评论

        本文标题:HttpClient delete 请求添加 body - an

        本文链接:https://www.haomeiwen.com/subject/nbwxaktx.html