我正在尝试通过 axios post 请求将文件发送到我的后端。
这是我目前的错误:
cherrypy._cperror.HTTPError: (415, 'Expected an entity of content type application/json, text/javascript')
根据我的阅读,我需要更改我的发布请求中的 Content-Type,我环顾四周我目前正在尝试这样做:
handleUploadButton(e){
const upload_file = this.state.file;
const formData = new FormData();
formData.append('file', upload_file);
const request = axios.post(someUrl, formData, {headers: {
"Content-Type": "application/json"}
})
.then(function (response) {
console.log('successfully uploaded', upload_file);
});
}
不确定是否相关,但所有这些都是通过 reactjs 表单发生的。 这是我当前的内容类型:Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryBwjjjGuJEySeXdRU
我不知道从这里去哪里。任何帮助将不胜感激。
最佳答案
SignIn = () => {
console.log('login clicked')
let data = JSON.stringify({
password: this.state.password,
username: this.state.email
})
axios.post('url', data, {
headers: {
'Content-Type': 'application/json',
}
}
)
}
关于javascript - 更改 axios header 中的 Content-Type 以修复 415 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41469119/