【发布时间】:2020-11-23 22:34:49
【问题描述】:
我想用 Angular Typescript 写这个请求:
http://localhost:8080/engine/oauth/authorize?client_id=admin&redirect_uri=http://localhost:9000/callback&response_type=code&scope=read_profile
当我在网络浏览器中打开此链接时,我会收到重定向响应:
http://localhost:9000/callback?code=7CLwgh
我尝试编写这个 Typescript 代码:
authCodeRequest(name: string, password: string): Observable<any> {
const body = new HttpParams()
.set('client_id', 'admin')
.set('redirect_uri', 'http://localhost:9000/callback')
.set('response_type', 'code')
.set('scope', 'read_profile');
const headers = new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
});
return this.httpClient
.get(environment.api.urls.auth.token, body.toString(), {
headers
})
.pipe(
map((response: Authorize) => {
console.log(data)
return true;
})
);
}
我在获取请求时收到此错误:TS2554: Expected 1-2 arguments, but got 3.
发出请求并从重定向链接参数code 获取结果的正确方法是什么?
【问题讨论】:
标签: angular typescript typescript1.8 http-request-parameters