【发布时间】:2016-12-16 05:31:29
【问题描述】:
当我在 Postman 上发出 GET 请求时,它成功发出 GET 请求:
var data = {
'Content-Type': 'application/json',
'vin': 'TESTVIN1234567890'
}
var myInit = {
method: 'GET',
mode: 'no-cors',
header: data,
};
fetch('http://www.localhost:8080/ota/upload/config/', myInit)
.then(result=>result.json())
.then(body=>{
console.log(body)
});
我收到以下错误(Uncaught SyntaxError 指向该行:.then(result=>result.json())):
所以我测试了http://jsonplaceholder.typicode.com/posts 的fetch 是否正确,它是否正确获取。
可能是什么问题?有什么我想念的吗?
编辑
我尝试了以下方法,但得到了'Network response was not ok. 并在 EDIT 2 中记录了以下内容:
fetch('http://www.localhost:8080/ota/upload/config/', myInit).then(function(response) {
if(response.ok) {
response.blob().then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
console.log(objectURL)
});
} else {
console.log('Network response was not ok.');
}
})
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
});
编辑 2 - 附加信息
【问题讨论】:
-
是
headers不是header -
@azium 试过但不幸的是没有用...
标签: javascript json reactjs fetch postman