rn-fetch-blob:如何通过正文中的参数发出发布请求?

时间:2020-07-30 17:53:27

标签: react-native react-native-android react-native-ios

您好,这可能是一个愚蠢的问题,但是我真的很困惑如何使用rn-fetch-blob发送带有内容的POST请求! https://github.com/joltup/rn-fetch-blob

这是我下面的POST请求代码,但抛出“无法符号化堆栈:堆栈为空”

const data = 'guid='+guid+'&username='+username+'&pass='+password;

let response = await RNFetchBlob.config({ trusty: certificate })
                .fetch('POST', httpOrhttps + "://" + ipAddress + ":" + portNumber + 
                  "/setup/", RNFetchBlob.base64.encode(data))
                .catch(async (error) => { console.error(error); });

但是我的GET帖子运行得很好

let response = await RNFetchBlob.config({ trusty: certificate})
               .fetch('GET', httpOrhttps + "://" + ipAddress + ":" + httpPort + "/setup/guid=" + guid 
                             + "&username=" + username + "&pass=" + password)
              .catch(async (error) => { console.error(error); });

依赖项:

"dependencies": {
    "@react-native-community/async-storage": "^1.11.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/bottom-tabs": "^5.7.1",
    "@react-navigation/drawer": "^5.8.5",
    "@react-navigation/material-bottom-tabs": "^5.2.13",
    "@react-navigation/native": "^5.7.0",
    "@react-navigation/stack": "^5.7.0",
    "react": "16.13.1",
    "react-native": "0.63.1",
    "react-native-device-info": "^5.6.3",
    "react-native-dropdown-picker": "^3.1.11",
    "react-native-elements": "^2.0.4",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-paper": "^4.0.0",
    "react-native-reanimated": "^1.9.0",
    "react-native-safe-area-context": "^3.1.1",
    "react-native-screens": "^2.9.0",
    "react-native-vector-icons": "^7.0.0",
    "rn-fetch-blob": "^0.12.0"
  },

1 个答案:

答案 0 :(得分:1)

Ciao,很难理解为什么,但最重要的是发生此错误的位置(我的意思是肯定会在rn-fetch-blob中发生,但准确地在何处发生)。我之所以这样说,是因为看着react native ExceptionsManager.js code,在函数reportException中,如果未接收到The stack is null(因此我们没有要分析的堆栈),它将返回prettyStack

我找到了this,但是它很旧,没有解决方案,除了3个众所周知的命令:

rm -rf ~/.rncache
watchman watch-del-all
npm start -- reset-cache

您可能已经尝试过了。

另一件事:您拥有rn-fetch-blob的最新版本。您可以尝试将其降级到10或11(可以这样做,因为您的本地反应值为0.63)。

就是这样。如果找到其他线索,我将在此答案中添加评论。