Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 5 Oauth2.0基本身份验证POST请求返回401(未经授权)_Angular_Oauth 2.0_Spring Security Oauth2 - Fatal编程技术网

Angular 5 Oauth2.0基本身份验证POST请求返回401(未经授权)

Angular 5 Oauth2.0基本身份验证POST请求返回401(未经授权),angular,oauth-2.0,spring-security-oauth2,Angular,Oauth 2.0,Spring Security Oauth2,我想使用post请求获取访问令牌 有人能帮我解释一下为什么会发生这种情况吗 let _httpParams = new HttpParams() .set("username","username") .set("password","password") .set("grant_type","password") let _httpHeader = new HttpHeaders(); _httpHeader = _httpHeader.append("Content-Type", "app

我想使用post请求获取访问令牌

有人能帮我解释一下为什么会发生这种情况吗

let _httpParams = new HttpParams()
.set("username","username")
.set("password","password")
.set("grant_type","password")

let _httpHeader = new HttpHeaders();
_httpHeader = _httpHeader.append("Content-Type", "application/x-www-form-urlencoded");
_httpHeader = _httpHeader.append("Authorization", "Basic " + btoa("username:password"));

return this._http.post(API_URL+'/oauth/token',{headers: _httpHeader,params: _httpParams})
我总是得到这个结果


您是否尝试使用postman或任何其他rest客户端调用此post请求?是的,在postman中,它正在工作。它正在使用相同的过程。我试着用angular做这件事,但它给了我这个错误。你能为你的http请求添加完整的代码吗?您的
授权
头肯定应该包含一个base64编码的客户id和密码字符串,而不是用户id和密码?