React-Native post和get请求

时间:2023-12-29 16:58:14

post:

 fetchData (title) {
fetch(REQUEST_URL, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: un,
password: pw
})
})
.then((response) => response.json())
.then((responseData) => {
if (responseData['isOK']==='ok') {
ToastAndroid.show('登录成功', ToastAndroid.SHORT)
} else {
ToastAndroid.show('登录失败', ToastAndroid.SHORT)
}
})
.done()
}
   responseData (response) {
return response.result.data
}

get:

 fetchData: function () {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData),
loaded: true
})
})
.done()
},