我正在使用firebase-auth并尝试使用axios获取用户数据。
当我像这样使用curl命令时,我可以成功地得到响应。
curl 'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=[API_KEY]' \
-H 'Content-Type: application/json' --data-binary '{"idToken":"[FIREBASE_ID_TOKEN]"}'https://firebase.google.com/docs/reference/rest/auth#section-get-account-info
我想知道如何使用axios更改此请求。我试过了,但没用。
const url = 'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=key
const token = localStorage.getItem('token');
const body = {"idToken":token}
axios
.get(url,token, {
headers: {'Content-Type': 'application/json'}, data: body
})
.then(res => {
console.log(res.data);
}).catch(error => {
alert("error");
})发布于 2020-12-24 14:45:51
您不能在GET请求中传递body,因此需要在body参数中使用Axios POST request作为pass token。如果您需要使用GEt请求进行同样的操作,请在url中传递令牌。
const token = localStorage.getItem('token');
const config = {
headers: { Authorization: `Bearer ${token}` }
};
const body = {"idToken":token}
axios.post(
'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=key',
bodyParameters,
config
).then(console.log).catch(console.log);发布于 2020-12-24 14:20:52
您不能在GET请求中添加正文,请将其更改为post并添加,如下所示
let response = await axios.post(url,{data:body});https://stackoverflow.com/questions/65434677
复制相似问题