簡體   English   中英

如何在 Angular 12 中提出補丁請求?

[英]How can I make Patch request in Angular 12?

如何通過補丁請求發送 JSON 數據以及連接到 API 的方法?

private baseUrlRemoveNotifications: string =
   "api/v1.0/UploadDownload/removeNotifications";  
public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
   let username = onlineUserModel.userName;
   const url = `${this.baseUrlRemoveNotifications}`;
   const options = {
     headers: new HttpHeaders({
       "Content-Type": "application/json",
     }),
   };
   return this.http.patch(
     `${this.baseUrlRemoveNotifications}`,
     username,
     options
   );
 }

您可以嘗試使用這段代碼:

public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
    let targetUsername = onlineUserModel.userName;
    const url =
      this.baseUrlRemoveNotifications +
      "/" +
      this.cookieService.get("username") +
      "/" +
      targetUsername;
    const body = {};
    const options = {
      headers: new HttpHeaders({
        "Content-Type": "application/json",
        "X-XSRF-TOKEN": this.cookieService.get("XSRF-TOKEN"),
      }),
    };
    this.http.patch<any>(url, body, options).subscribe((data) => {
      console.log("hi this is put request", data);
    });
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM