从angular里传值Auth Api
问题是Auth api不接受json格式的 form post, 这种情况下 Http Header里的Content-Type必须是 'application/x-www-form-urlencoded'
headers: {Authorization: token,'Content-Type': 'application/x-www-form-urlencoded',}
然后 angular必须把Http Param用fromObject转一下
const params = new HttpParams({fromObject: {grant_type: 'client_credentials',}});
完整代码如下
public getApplicationToken(): Observable {const applicationToken = this.cookieService.get(this.cookieKey);if (!Strings.isNullOrWhiteSpace(applicationToken)) {return of(applicationToken);}const url = '/api/gspAuth/';const idSecurity = 'Basic ' + btoa(`${applicationId.client_id}:${applicationId.client_sec}`);const params = new HttpParams({fromObject: {grant_type: 'client_credentials',}});return this.http.post(url, params,{headers: {Authorization: idSecurity,'Content-Type': 'application/x-www-form-urlencoded',}},).pipe(map(response => this.mapGetTokenResponse(response)),catchError(ex => this.mapGetTokenResponseError(ex, 'Failed to get application token.')),tap(data => {this.log.info(`Get application access token, response:${JSON.stringify(data)}`);}));}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
