【发布时间】:2018-09-10 15:29:52
【问题描述】:
我是 react-native 的新手,我正在向服务器发送请求,并希望在同一个块中获取响应和正文,以便我可以将这两个项目发送到另一个函数,我的 fetch 方法看起来像
send_request = (data) =>{
url = BASE_URL + "some/url.json"
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
user: {
email: data.email,
full_name: data.name,
}
})
}).then((response) => {
//how can I get response body here so that I can call following method
// this.use_response(responsebody, response.headers)
return response.json()
}).then((responseJson) => {
// or how can I get response headers here so that I can call following fuction
// this.use_response(responseJson, headers)
return responseJson
}).catch((error) => {
console.log(error)
});
}
如何同时使用两者,请帮助提前谢谢!
【问题讨论】:
标签: reactjs react-native