React native Post请求中的400(错误请求),axios
我向这个url发出了一个post请求http://localhost:8000/files/关于邮递员。这是成功的。但是,在我的react前端尝试相同的操作会产生400(错误请求错误)。它还表示未捕获(承诺中)错误:请求失败,状态代码为400 这是我的密码: submitHandlerReact native Post请求中的400(错误请求),axios,react-native,axios,React Native,Axios,我向这个url发出了一个post请求http://localhost:8000/files/关于邮递员。这是成功的。但是,在我的react前端尝试相同的操作会产生400(错误请求错误)。它还表示未捕获(承诺中)错误:请求失败,状态代码为400 这是我的密码: submitHandler submitHandler(event) { event.preventDefault(); const headers = { 'Content-Type':
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>
<input type="file" name="file" onChange={this.onFileChange}/>
</div>
我尝试了几个没有解决方案的链接。我很高兴能在这里得到帮助。您的服务是什么。如果是express,请确保允许您的服务器接受表单数据。您如何存储图像?你在用mutler吗?400系列错误意味着客户端发送的数据不符合服务器接受的格式。我的API是使用Django构建的。您的服务内置于什么。如果是express,请确保允许您的服务器接受表单数据。您如何存储图像?你在用mutler吗?400系列错误意味着客户端发送的数据不符合服务器接受的格式。我的API是使用Django构建的。