简体   繁体   English

刚开始反应原生,实现 api 集成但返回 html

[英]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.

相关问题 集成React Native和Express JS Restful API - Integration React Native and Express JS Restful API React.js中的奇怪错误-尽管未被调用,Fetch API仍从index.html返回HTML - Strange Error in React.js — Fetch API is returning HTML from index.html, despite not being called React Native Fetch API不返回我的调用 - React Native Fetch API not returning my calls 获取 API 在反应原生中返回旧数据 - Fetch API returning old data in react native 在平面列表中实现搜索栏以搜索 api 数据反应原生 - Implementing searchbar into flatlist to search api data react native Docusign 与 React Native 的集成 - Docusign Integration with React Native React Native:提取api调用返回不适当的响应 - React Native: Fetch api call is returning inappropriate response Expo / React Native Fetch API不返回文本/纯文本数据 - Expo/React Native Fetch API is not returning text/plain data currentFocusedField 正在被弃用,在 React Native 中实现更改后显示使用 FocusedInput 错误 - currentlyFocusedField is being deprected use FocusedInput error showing after implementing change in React Native 为什么我的 API 数据在 React Native 中被调用了 53 次? - Why is my API data being called 53 times in React Native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM