【发布时间】:2018-04-04 09:11:55
【问题描述】:
我需要发出请求以获取 oAuth2 身份验证服务器中的令牌。
我可以在邮递员中发出请求并获取令牌,但不能从角度 4 发出相同的请求。
我的 CORS 配置良好,因为其他请求运行良好。
这里是 HTTP 请求的详细信息。
POST /oauth/token HTTP/1.1
Host: localhost:8080
Authorization: Basic YXBwbGljYXRpb246c2VjcmV0
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Postman-Token: 9f9582e9-fe73-499f-d7f7-82498a974e39
grant_type=password&username=pedroetb&password=password
在 Angular 4 中,我尝试过这种方式
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append("Authorization","Basic YXBwbGljYXRpb246c2VjcmV0");
var obtainTokenUrl = 'http://localhost:8080/oauth/token';
this._http.post(obtainTokenUrl + "?grant_type=password&username=pedroetb&password=password", null, {headers: headers}).subscribe(response => {
console.log(response);
});
但这不起作用。
那么我怎样才能从 angular 4 发出同样的请求呢?
【问题讨论】:
标签: node.js angular oauth-2.0 http-post