【发布时间】:2018-03-12 15:55:57
【问题描述】:
我想向 Azure 上运行的 REST API 发出 POST 请求,并且我想通过 POST 请求传递一个 javascript 对象。但响应显示 415 错误代码 Unsupported Media type。我确实尝试将“内容类型”更改为“应用程序/json”,但得到了相同的响应。
componentDidMount() {
const bodyFormData = new FormData();
bodyFormData.set('id', 30958);
axios({
method: 'post',
url: 'https://example./api/example/GetExamplData',
data: bodyFormData,
config: { headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}}
})
.then((response) => {console.log(response)})
.catch(error => {console.log( 'the error has occured: ' + error) })
}
【问题讨论】:
-
不确定,但这是一个快速的镜头:将您的
headers设置为独立属性(不要将其包裹在config中)
标签: javascript reactjs rest axios