info.plist根据以下错误消息,我需要在我的设置中启用HTTP模式?
传输安全性阻止了明文HTTP(http://)资源加载,因为它不安全.可以通过应用程序的Info.plist文件配置临时例外.
假设我的域名是example.com.
我正在使用Xcode 4.5,我的iPhone模拟器无法连接到互联网.互联网正在我的所有Mac浏览器上工作,但iPhone模拟器无法连接.我尝试在iPhone模拟器中在Safari中打开一个网页,但没有帮助.
我正在尝试使用react-native、axios 和 Expo 发送 JSON 数据,但是当我在应用程序上按“发送”时,我收到此警告:
可能未处理的承诺拒绝,错误:网络错误
当我尝试通过 POSTman 发送通知(JSON)时,我的 API 正确接收通知(JSON),但是当我尝试使用 axios 发送通知时,我收到上述警告消息,所以 React 可能没有正确发送数据。
export default class NotificationsInput extends React.Component {
state = {
token: '',
title: '',
body: ''
}
handleToken = event => {
this.setState({ token: event.target.value })
}
handleTitle = event => {
this.setState({ title: event.target.value })
}
handleBody = event => {
this.setState({ body: event.target.value })
}
handleSubmit = event => {
event.preventDefault();
let notification = JSON.stringify({
token: this.state.token,
title: this.state.title,
body: this.state.body
}) …Run Code Online (Sandbox Code Playgroud) 我正在测试一个react本机应用程序(在xcode模拟器v9.2/xcode 7.2.1中的OS X Yosemite上).我收到Network request failed以下代码的错误.具有正确appid的实际url在浏览器中运行良好,并以json格式提供正确的信息,并且promise/api调用看起来很好.
我不在防火墙后面.我已经尝试对连接进行故障排除,并Allow HTTP Services在开发人员设置中激活,但我仍然收到错误.
知道这里的问题是什么吗?实际错误如下:
-- There has been a problem with your fetch operation: Network request failed
-- Api call error = Network request failed
Run Code Online (Sandbox Code Playgroud)
这是api.js代码:
var _ = require('lodash');
var rootUrl = 'http://api.openweathermap.org/data/2.5/weather?APPID=xxxxxxxxxxxxxxxxxxxxxx';
var kelvinToF = function(kelvin) {
return Math.round((kelvin - 273.15) * 1.8 + 32) + ' ?F'
};
var kelvinToC = function(kelvin) {
return Math.round(kelvin - 273.15) + ' ?C'
};
module.exports = function(latitude, longitude) {
var …Run Code Online (Sandbox Code Playgroud) 在 ReactNative 组件中,当我按下按钮时,执行此函数时出现“可能的未处理的承诺拒绝”错误:
async onAdd(item) {
try {
const response = await fetch('url', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
event_id: item.id,
event_type: item.event_type,
})
});
const responseJson = await response.json();
} catch (error) {
error(error);
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,因为它在 try / catch 块中。
更新
这是错误函数:
function error(value) {
if (console) {
console.error(value)
}
}
Run Code Online (Sandbox Code Playgroud) react-native ×3
javascript ×2
xcode ×2
async-await ×1
axios ×1
expo ×1
ios ×1
ios10 ×1
ios9 ×1
iphone ×1
promise ×1
reactjs ×1
xcode4.5 ×1
xcode7 ×1