react-native - Axios 向我抛出“未经授权”
问题描述
这很奇怪,因为邮递员允许我进行 POST,但 react 不允许。令牌是有效的,当被调用时,令牌会打印到控制台
export default class Create extends Component {
//url = 'http://127.0.0.1:5000/wtw/articles/'
constructor(props) {
super(props);
this.state = {
//author?
title: '',
description: '',
//image: ,
//token: null
};
}
handleCreate = async () => {
const { title, description, image } = this.state;
let token = await AsyncStorage.getItem('token');
axios
.post('http://127.0.0.1:5000/wtw/articles/', {
headers: {
Authorization: 'Token ' + token,
},
data: {
title: title,
description: description,
},
})
.then(async (Response) => {
console.log(Response);
})
.catch((err) => {
console.log();
console.log(err);
console.log(token);
});
};
}
解决方案
推荐阅读
- haskell - 在dhall(Haskell)中编码`Map([Text],[Text])Text`
- android - Android:从应用程序基础语言环境获取字符串资源
- dialogflow-es - 有没有办法使用 google 客户端库上的操作使用 dialogflow 应用程序实例直接设置履行消息
- javascript - 转换缩放 html 元素并使用 javascript setTimeout 函数进行反转换
- firebase - Flutter Firebase 动态链接在 facebook 上不起作用
- c# - 从 WebApi 向客户端返回错误消息时抛出异常是不好的做法吗?
- android - Android(Unity)中的深度着色器错误:材质中的伪影和故障
- java - 在 Android 中选择 Spinner 选项时如何显示不同的文本视图
- go - 去编译:从可执行文件中删除个人信息
- node.js - 使用 NPM 安装