[英]Being new to react native, implementing api integration but returning html
我正在將 api 集成到 react native 中,但是響應以 html 形式出現,而它在 postman 上運行良好。 這是我的代碼
const params = new URLSearchParams();
params.append('userNameOrEmailAddress', 'abc@123.pqr');
params.append('password', '123456');
console.log("params", params);
axios.post(
apiUrl,
params,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
}).then(response => {
console.log("response", response.data);
const { targetUrl } = response.data;
console.log("target", targetUrl);
props = targetUrl;
console.log("props", props);
Alert.alert(
"App",
"User success",
[
{
text: "Ok",
onPress: () =>
navigation.navigate('MainView' , {
url: targetUrl
})
},
],
{
cancelable: true,
onDismiss: () =>
Alert.alert(
"This alert was dismissed by tapping outside of the alert dialog."
),
}
)
}).catch(error => {
console.log("error", error);
// const errors = {};
// this.setState({
// errors: errors,
// });
});
};
我嘗試了很多方法,但這里的更改無法按預期工作,api 有時工作正常,但在其他時候,它返回 html。 在這種情況下,任何幫助都會真正緩解。
這個問題是博覽會應用程序緩存。 實際上,當我在安裝了新博覽會的不同設備上運行它時,它起作用了。 這聽起來很奇怪,但它確實發生了。 現在每次遇到這個問題時,我都會卸載 expo 並重新安裝,它可以工作。 不知道確切的問題,但這個解決方案可能是暫時的,對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.