django - 服务器响应状态为 415(不支持的媒体类型) - vue.js 和 python django
问题描述
我正在发送注册请求,并收到此错误:
{"errors":[{"detail":"请求中不支持的媒体类型 \"application/json;charset=UTF-8\"。","source":{"pointer":"/data"},"status ":"415"}]}
这就是我在 vue.js 中发送数据的方式:
import {instanceAxios} from '@/services/interceptor';
const registration = async ({commit}, data) => {
try {
let resp = await instanceAxios.post('/account/register/', data);
const token = resp.data.token;
localStorage.setItem('token', token);
instanceAxios.defaults.headers.common['Authorization'] = `Token ${token}`;
commit('AUTH_SUCCESS', resp.data);
return resp;
} catch (e) {
localStorage.removeItem('token');
throw e;
}
};
我得到这个错误。
这是我的请求在浏览器中的外观:
内容类型是应用程序的非常有趣的事情我也可以从后端注册方法中为您提供代码 https://pastebin.com/74zXjejV
PS:我不知道为什么,但我得到内容类型 application/d.json - 这很奇怪
解决方案
415 错误意味着您的有效负载无效,请参见此处。
如果你发送 json 试试这个
instanceAxios({
method: 'post',
url: '/account/register/',
headers: {'Content-Type': 'application/json'}
});
代替
instanceAxios.post('/account/register/', data);
并检查您的身体是否有效
推荐阅读
- python - Pandas groupby rank date time
- c# - 面临将 XML 转换为 Object 的问题
- reactjs - 使用 CDN 反应过渡组
- javascript - TypeError: Cannot read property '0' of undefined from the Array using AngularJS
- ruby - Program working, but I'm still getting a NoMethodError 'length' nil
- odoo - 确认发票时的线程
- python - Pandas DateTime Conversions with Math Between Column
- h2o - h2o.cor 如何处理分类数据
- python - compare two csv files and do something if there is a match between two fields
- c# - ArgumentException“参数不正确”