我正在使用fetch从我的api检索数据,根据日志返回的响应为:
{
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "[{\"text\": \"1\", \"email\": \"test1@asfsaf.com\"}, {\"text\": \"3\", \"email\": \"test3@asfsaf.com\"}, {\"text\": \"2\", \"email\": \"test2@asfsaf.com\"}]"
}
但是在调试时有角度:
body: null
bodyUsed: false
headers: Headers {append: function, delete: function, get: function, has: function, set: function, …}
ok: false
redirected: false
status: 0
statusText: ""
type: "opaque"
url: ""
我用来调用api的代码是:
getLastReviews()
{
return fetch (
ApiService.url ,
{
headers: {
'Content-Type': 'application/json',
},
method: 'GET',
mode: 'no-cors',
},
)
}
组件上的代码:
constructor(private api : ApiService) { }
recent_reviews
ngOnInit()
{
this.getRecent()
}
async getRecent(){
let res = await this.api.getLastReviews()
debugger
let data = await res.json()
this.recent_reviews = data
}
}
我尝试使用邮递员调用此url,并且它没有任何错误,尽管在浏览器中输入url时,也会得到一个空的响应-{}。 有谁知道问题可能在哪里?谢谢!