HarmonyOS 在应用中无法访问外部网络资源。
配置文件代码如下:
// 在 config.json 中添加网络权限
{
"module": {
"reqPermissions": [
{
"name": "ohos.permission.INTERNET"
}
]
}
}
// 发起网络请求
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
确保网络请求的代码正确无误,并处理了可能的错误情况