[英]Being new to react native, implementing api integration but returning html
I am integrating api in react native but the response comes in html while it runs fine on postman.我正在将 api 集成到 react native 中,但是响应以 html 形式出现,而它在 postman 上运行良好。 Here is my code
这是我的代码
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,
// });
});
}; };
I have tried many methods but changes here don't work as desired, The api works fine sometimes but at other times, it returns html.我尝试了很多方法,但这里的更改无法按预期工作,api 有时工作正常,但在其他时候,它返回 html。 Any help in this case will be really relieving.
在这种情况下,任何帮助都会真正缓解。
The issue with this was expo app cache.这个问题是博览会应用程序缓存。 Actually when I run this on a different device with new expo installed, it worked.
实际上,当我在安装了新博览会的不同设备上运行它时,它起作用了。 That sounds strange, but it happened.
这听起来很奇怪,但它确实发生了。 Now every time I run into this issue, I uninstall expo and reinstall, it works.
现在每次遇到这个问题时,我都会卸载 expo 并重新安装,它可以工作。 Don't know the exact issue but this solution, might be a temporary one, is working for me.
不知道确切的问题,但这个解决方案可能是暂时的,对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.