我目前在HttpClient与Axios 之间遇到问题
当我使用这个代码时
const requestBody = {
grant_type: 'refresh_token',
client_id: environment.APP_COGNITO_CLIENT_ID,
refresh_token: this.storage.get("auth").refresh_token,
};
const params = {
baseURL: "https://testing.auth.eu-west-2.amazoncognito.com",
url: '/oauth2/token',
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
data: qs.stringify(requestBody),
};
const result = await axios.request(params);
我可以刷新我的代币
但是当我使用这个代码时
try {
let refresh_token = this.storage.get("auth").refresh_token;
let access_token = this.storage.get("auth").access_token;
let queryString = `client_id=${environment.APP_COGNITO_CLIENT_ID}&refresh_token=${refresh_token}&grant_type=refresh_token`;
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }),
observe: 'response'
};
// let result = await lastValueFrom(this.$http.post<any>(test, { headers: headers }));
let result = await lastValueFrom(this.$http.post<any>(environment.APP_COGNITO_TOKEN_ENDPOINT + '/oauth2/token?' + queryString, httpOptions));
return "Token Refresh Success";
} catch (error: any) {
return "error";
}
我出错了无法读取响应405我在互联网上发现这可能是头部问题,
我想用棱角分明的方式。但角度本身似乎有问题。
我尝试附加,设置
在标题中,它仍然不起作用。有什么有用的想法吗?
可能是因为第二个参数是主体/数据,第三个参数是标题。所以应该是这样的:这个$http.post(environment.APP_COGNITO_TOKEN_ENDPOINT+'/oauth2/TOKEN?'+queryString,null,httpOptions)--------或广告您的数据而不是null
通过零点十二