gpt4 book ai didi

react-native - react native 并需要 ('http' )

转载 作者:行者123 更新时间:2023-12-03 14:14:26 25 4
gpt4 key购买 nike

React Native 附带的节点核心似乎不包含节点核心 http。是否可以在 React Native 中添加和使用它?

提前谢谢了。

最佳答案

根据 react-native 团队的说法,

For this specific case you'll likely want to use the fetch API which is provided by the environment. React Native does not run inside of the node runtime.


fetchhttp 类似.以下是如何使用它的简短示例:

// Using fetch to POST

fetch(requestURL, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: this.state.input,
})
})

// Using fetch to GET

fetch(requestURL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData),
loaded: true,
});
})
.done();

关于react-native - react native 并需要 ('http' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29371694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com