原文
fetch("http:/example.com", {method: "POST",
body: JSON.stringify(
{
uname: uname,
password: password
}
)
})
.then((response) => response.json())
.then((responseData) => {
AlertIOS.alert(
"POST Response",
"Response Body -> " + JSON.stringify(responseData.body)
)
}).done();
this.props.navigation.navigate("Home")
};
修改后的 response.text()代替response.json()
fetch("http:/example.com", {method: "POST",
body: JSON.stringify(
{
uname: uname,
password: password
}
)
})
.then((response) => response.text())
.then((responseData) => {
AlertIOS.alert(
"POST Response",
"Response Body -> " + responseData
)
}).done();
this.props.navigation.navigate("Home")
};
本文展示了如何使用fetch API进行POST请求,包括发送JSON数据及处理响应的方法。通过两个示例,分别演示了使用response.json()和response.text()获取响应数据的过程。
507

被折叠的 条评论
为什么被折叠?



