我开发了一个API(节点js,express和firebase)来在我的原生应用中使用它来反应我的API的结构: API:允许您选择一些尊重特定条件的用户,并在调用允许修改数据库firebase中字段的函数后:当我在浏览器上测试时,API工作得非常好。
以下是我的API的结构:
router.get ('/: senderID /: numberOfShare /: drop', function (req, res, next) {
// Code that allows users to be selected from the database FOREACH {
// call to a function (function2) which allows to modify the data of users in the BDD
}
// define the function2 here { modify user data in the database
}
}
我的问题是:如何从我的本机应用程序中正确利用我的API?
我做了一个测试,但没有工作。
测试:
shareDrop (drop, parent) {
fetch ('192.168.1.4:3000/users/senderID/numberOfShare/drop',
{ method: 'GET',
headers: {
Accept: 'application / json',
'Content-Type': 'application / json',
}
params: JSON.stringify
({
senderID: this.state.uid,
numberOfShare: 'parent.state.numberOfShare',
drop: drop
}),
});
}
答案 0 :(得分:0)
确保您的info.plist
允许localhost或其他API与之通信。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
Here是我构建的一个回购,用于演示react-native
应用如何与node
服务器和mongo
数据库进行通信。也许你可以在那里找到一些灵感。