gss 6 react native和django后台数据交互 - nuanxin1111/react GitHub Wiki
###RN使用fetch的方式发送POST请求 1 先定义URL
const HOMEPAGE_URL = "http://www.xingwenpeng.com/doctor/info/";
2 fetch发送post请求
fetch(HOMEPAGE_URL,{
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
doctor_id: '2',
})
})
.then((response) => {
return response.json();
})
.then((responseText) => {
#responseText就是获取到的数据
console.log(ResponseText);
})
.catch((error) => {
console.log(error);
})
.done();
3 django后台获取数据
data = json.loads(request.body)