Redux fetch 返回空
Redux fetch is returning empty
我对 AWS API 网关端点的 redux 提取调用返回空。
Curl、Postman 或仅在浏览器中,响应正确。
export function getRequest() {
return function (dispatch) {
return fetch("apiGatewayURL", {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}).then(body => console.log("Calling ",JSON.stringify(body)))
}
}
对我在这里做错了什么有什么建议吗?
阅读前需要调用json()
或text()
函数
export function getRequest() {
return function (dispatch) {
return fetch("apiGatewayURL", {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(body => console.log("Calling ",JSON.stringify(body)))
}
文档: https://github.com/matthew-andrews/isomorphic-fetch
fetch()
文档: https://github.com/github/fetch
将 Accept
放入 headers 并首先在响应中调用 .json()
。
export function getRequest() {
return function (dispatch) {
return fetch("apiGatewayURL", {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(response => response.json())
.then(body => console.log("Calling ", body))
}
}
我对 AWS API 网关端点的 redux 提取调用返回空。
Curl、Postman 或仅在浏览器中,响应正确。
export function getRequest() {
return function (dispatch) {
return fetch("apiGatewayURL", {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}).then(body => console.log("Calling ",JSON.stringify(body)))
}
}
对我在这里做错了什么有什么建议吗?
阅读前需要调用json()
或text()
函数
export function getRequest() {
return function (dispatch) {
return fetch("apiGatewayURL", {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(body => console.log("Calling ",JSON.stringify(body)))
}
文档: https://github.com/matthew-andrews/isomorphic-fetch
fetch()
文档: https://github.com/github/fetch
将 Accept
放入 headers 并首先在响应中调用 .json()
。
export function getRequest() {
return function (dispatch) {
return fetch("apiGatewayURL", {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(response => response.json())
.then(body => console.log("Calling ", body))
}
}