【发布时间】:2023-03-05 01:56:01
【问题描述】:
所以我向服务器发送了一些参数,但我无法获得 response.status。此外,response.ok 也不起作用。
this.state = {
value: "",
focused: false,
text: "",
uuid: this.props.navigation.state.params.uuid,
codeConf: ''
};
}
sendCode(uid, code) {
fetch(' /', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"authentication": uid, "code": code})
})
.then(response => {
if (response.ok){
console.log("Code is good")
}
else
{
console.log("Code is not good Cyka")
}
})
}
render() {
return (
<Button
title="Send code"
onPress=
{(code) => {this.sendCode(this.state.uuid, this.state.code)}}/>
</View>
)
}
}
如果验证了短信代码,基本上服务器返回“200 OK”响应,否则返回 400。所以,我正在考虑仅在 response.status 为 200 或 response.ok 为真时继续用户。 谢谢!
编辑#1: 我用邮递员测试过请求,一切都很好。
【问题讨论】:
-
您可以添加整个响应吗?
-
在开发工具中调试并查看
response的值。这应该告诉你所有你需要知道的。或者注销整个响应,这样您就可以真正看到它有哪些字段。 -
这里是整个响应: { "data": { "id": "ab42c542-66db-4df2-974f-5fd17edfb76b", "gender": null, "status": 1, "surname ": null, "name": null, "middlename": null, "borned_at": "2019-02-25T23:36:49.010638", "avatar": null, "city": null, "authentication": "ce1d847c -e049-44aa-9a2c-105548bf81f7" } }
-
您可能还想添加您在邮递员中看到的响应。
标签: javascript react-native jsx