angular postman不同的body type需要什么样的请求格式
作者:互联网
1. postman的body请求格式为 raw (application/json), 则angular请求方式
const headers = new HttpHeaders().set("Content-Type", "application/json; charset=UTF-8").set("Accept", "*/*" ); let body1 = { "access_token" : environment.token } this.httpClient.post(environment.baseUrl + "ResourceV3/getCategoryList.mvc",body1,{headers}) .subscribe( (data:any) => { this.spinner.hide(); if(data["statusCode"] == '0'){ }else{ this.snackBar.open('Something went wrong. Please try again later.', '×', { panelClass: 'error', verticalPosition: 'top', duration: 5000 }); } }, error => { this.spinner.hide(); this.snackBar.open('Something went wrong. Please try again later.', '×', { panelClass: 'error', verticalPosition: 'top', duration: 5000 }); });
2. postman的body的请求格式为application/x-www-form-urlencoded,则angular的请求方式为
const headers = new HttpHeaders().set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8").set("Accept", "*/*" ); let body1 = new HttpParams({ fromObject : { "access_token" : environment.TOKEN } }); this.httpClient.post(environment.baseUrl + environment.API.getCategoryList,body1,{headers}) .subscribe( (data:any) => { this.spinner.hide(); if(data["statusCode"] == '0'){ this.categoryList=data["returnData"]["datas"] this.categoryList = this.categoryList.sort((a:any, b:any)=>a.name.localeCompare(b.name)); }else{ this.snackBar.open('Something went wrong. Please try again later.', '×', { panelClass: 'error', verticalPosition: 'top', duration: 5000 }); } }, error => { this.spinner.hide(); this.snackBar.open('Something went wrong. Please try again later.', '×', { panelClass: 'error', verticalPosition: 'top', duration: 5000 }); });
标签:body,spinner,set,postman,data,Please,environment,error,type 来源: https://www.cnblogs.com/jahoon/p/15692762.html