react-native - 发布请求中的 400(错误请求),axios
问题描述
我在 postman 上向这个 url http://localhost:8000/files/发出了 post 请求 。这是成功的。但是,在我的 react 前端尝试相同的操作会产生400 (bad request error)。它还说Uncaught (in promise) Error: Request failed with status code 400
这是我的代码:
提交处理程序
submitHandler(event) {
event.preventDefault();
const headers = {
'Content-Type': 'application/json',
}
const data = new FormData()
data.append('file', this.state.pdf_file)
console.warn(this.state.pdf_file);
axios
.post("http://localhost:8000/files/", data, {headers: headers})
.then(res => {
console.warn(res);
})
onFileChange
onFileChange(event) {
this.setState({
pdf_file: event.target.files[0],
});
};
文件上传div
<div>
<input type="file" name="file" onChange={this.onFileChange}/>
</div>
我尝试了几个没有解决方案的链接。我很乐意在这里得到帮助。
解决方案
推荐阅读
- python-3.x - 如果在 Pandas 中使用 -Else 条件在单独的文件夹中创建 CSV
- multithreading - 下面的代码线程不安全吗?是这样,我怎样才能让一个可能的结果更有可能出来?
- go - 在 HashiCorp 保险库中搜索值
- spring-boot - 如何在 Spring Boot 中为 JMS 客户端编写 JUnit 测试用例
- r - 无法使用 facet_wrap 获得 geom_text 标签
- git - 变基和合并导致具有相同更改的两个提交
- c# - 使用 jsTree,如果选择/突出显示该父项,我如何将新项目添加到现有父项的子组?
- webpack - Webpack 将所有未使用的导出导入到包中
- android - Firebase 本地模型抛出“没有找到内置操作码‘CONV_2D’版本‘2’的操作”
- swift - SwiftUI:无法创建一个其他所有视图都可以看到的简单布尔值