不要在 api 上设置 POST 请求,得到 406 Not Acceptable。尝试使用 axios 并得到 406 错误。有人认为是 axios 问题的原因。然后我尝试使用 fetch() 并再次遇到 406 错误。
我认为没有设置标题Content-Type
,当我发送 his-get 400 Bad Request 和标签预览时Unauthorized header content-type
。
需要你的帮助,我做错了什么?感谢大家的帮助。
- 环境:node v8.9.4,chrome 64.0.3282.119,Ubuntu 16.04
- axios 版本:0.16.2
- Vue.js 2.4.2
- Vue-axios 2.0.2
- api平台/api包:1.0
- Symfony 4.0.4
第一个示例 fetch() 代码:
const json = JSON.stringify({
a: 1,
b: 2,
});
fetch('http://localhost:8080/api/products', {
method: 'POST',
headers: {
// 'Content-Type': 'application/json',
},
body: json,
});
第二个示例 Axios 代码:
const data = JSON.stringify({
data: this.cardData.brand,
});
const configAxios = {
headers: {
// 'Content-Type': 'application/json',
},
};
axios.post('api/products', data, configAxios)
.then((res) => {
this.cardData.brand = res.data;
console.log(res);
})
.catch((err) => {
console.warn('error during http call', err);
});