"JSON :未识别的令牌‘<’“错误在点击api时显示。下面附加了注释*:响应是JSON格式。
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")
};
请帮帮忙。谢谢,
发布于 2018-06-14 03:19:36
最后,下面的代码起作用了。问题是身体参数。
fetch("http:/example.com", {method: "POST",
body: "uname=value1&password=value2" // <-- Post parameters
})
.then((responseData) => {
AlertIOS.alert(
"POST Response",
"Response Body -> " + JSON.stringify(responseData.body)
)
}).done();
this.props.navigation.navigate("Home")
};
发布于 2019-02-14 09:19:08
这意味着您正在从服务器获得Html响应,可能是404或500错误。而不是使用response.json()
response.text()
,您将得到文本中的html。
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")
};
发布于 2018-06-13 05:30:02
您可以尝试将头添加到获取api中,因为它会将记录发布到url。
var dataObj = {}
dataObj.uname = uname,
dataObj.password = password
fetch("http:/example.com", {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*', // It can be used to overcome cors errors
'Content-Type': 'application/json'
},
body: JSON.stringify(dataObj)
})
.then((response) => response.json())
.then((responseData) => {
AlertIOS.alert(
"POST Response",
"Response Body -> " + JSON.stringify(responseData.body)
)
}).done();
this.props.navigation.navigate("Home")
};
https://stackoverflow.com/questions/50837479
复制相似问题