【发布时间】:2019-08-28 23:07:43
【问题描述】:
你好我正在使用这个 json 服务器https://github.com/typicode/json-server 我可以在 postmman 中发布数据,并且它的工作良好,例如对象
{
"mainTab":{
"m_actual":0,
"m_refresh":2000,
"m_actual":0,
"m_refresh":4000
}
}
带有标题Content-Type: application/json
到我的服务器正在运行http://35.195.249.40:3004/users
一切正常
但在我的 nativescript/vue 应用程序中,我无法发出发布请求 - 它给出 304 响应
updateJsonData(){
const data = {
m_actualHP: 0,
m_refreshHP: 2000,
m_actualMP: 666666,
m_refreshMP: 4000,
}
axios.post('http://35.195.249.40:3004/users', data, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
},
我也尝试了获取请求并且它响应 '解析失败:' [TypeError: Network request failed: java.io.IOException: Cleartext HTTP traffic to not allowed]
updateJsonData(){
fetch('http://35.195.249.40:3004/users', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"title": "Add a blogpost about Angular2",
"dueDate": "2015-05-23T18:25:43.511Z",
"done": false
})
}).then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json: ', json)
}).catch(function(ex) {
console.log('parsing failed: ', ex)
});
},
【问题讨论】:
标签: javascript node.js json vue.js nativescript