Javascript 获取415不支持的媒体类型REST客户端的响应状态
我想向Azure上运行的RESTAPI发出POST请求,并希望通过POST请求传递javascript对象。但响应显示415错误代码不支持的媒体类型。我确实尝试过将“Content Type”更改为“Application/json”,但得到了相同的响应 componentDidMount(){Javascript 获取415不支持的媒体类型REST客户端的响应状态,javascript,reactjs,rest,axios,Javascript,Reactjs,Rest,Axios,我想向Azure上运行的RESTAPI发出POST请求,并希望通过POST请求传递javascript对象。但响应显示415错误代码不支持的媒体类型。我确实尝试过将“Content Type”更改为“Application/json”,但得到了相同的响应 componentDidMount(){ 通常RESTAPI使用json mediaType,请确保您的服务器 试试这个: const bodyFormData = { "name":"John", "age":30, "city":"New
通常RESTAPI使用json mediaType,请确保您的服务器 试试这个:
const bodyFormData = { "name":"John", "age":30, "city":"New York"};
axios({
method: 'post',
url: 'https://example./api/example/GetExamplData',
data: JSON.stringify(data),
config: { headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}}
})
.then((response) => {console.log(response)})
.catch(error => {console.log( 'the error has occured: ' + error) })
}
确保
const bodyFormData=new FormData();
返回json。不确定,但这里有一个快速提示:将标题设置为独立属性(不要将其包装在config
中)
const bodyFormData = { "name":"John", "age":30, "city":"New York"};
axios({
method: 'post',
url: 'https://example./api/example/GetExamplData',
data: JSON.stringify(data),
config: { headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}}
})
.then((response) => {console.log(response)})
.catch(error => {console.log( 'the error has occured: ' + error) })
}