Ho un'app, che im utilizzando fetch per autenticare l'utente. Funzionava fino a pochi giorni fa e non ho cambiato nulla. appena aggiornato da reagire 0,27 a 0,28, non recuperare non funziona.Fetch React-Native, Richiesta di rete fallita. non usando localhost
ho cercato per quasi 2 giorni e ho letto quasi tutte le domande in StackOverflow. la maggior parte degli utenti cerca di recuperare qualcosa da localhost e quando la cambiano in un vero indirizzo IP, la fanno funzionare. ma non sto recuperando nulla da localhost, anche il mio codice funzionava.
Ecco il mio codice:
fetch('http://somesite.com/app/connect', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'language':'en-US',
'Authorization': 'Bearer ' + access_token,
},
body: JSON.stringify({
uid: uid,
refresh_token: refresh_token,
token: access_token,
device: device_id,
device_name: device_name,
})
})
.then((response) => response.json())
.then((responseData) => {
console.log(JSON.stringify(responseData.body))
})
.catch((err)=> {
console.log('Some errors occured');
console.log(err);
})
.done();
ho provato a fare alcuni nuovi progetti, semplici, appena usato un semplice prendere ad esempio fro tutorial, ha dato lo stesso errore. Ho provato ad aprire il mio sito Web che im cercando di connettersi ad esso, tramite browser in emulatore, funziona, ma sembra attraverso il mio, l'applicazione non può connettersi a qualsiasi sito web/IP. dà questo errore in console chrome:
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:28193:8)
at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:14591:15)
at XMLHttpRequest.setReadyState (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29573:6)
at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29431:6)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29506:52
at RCTDeviceEventEmitter.emit (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:13428:23)
at MessageQueue.__callFunction (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11999:23)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11906:8
at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11857:1)
at MessageQueue.callFunctionReturnFlushedQueue (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11905:1)
in realtà io ho lo stesso problema di questo utente qui: React-native network request always fails
UPDATE: info.plist from xcode
qualsiasi aiuto sarà apprezzato!
Che cosa hai in 'NSAppTransportSecurity' nel file Info.plist per la tua app? –
Grazie per la risposta. ho aggiunto screenshot al post principale. anche tu puoi vederlo qui http://i.stack.imgur.com/vvqMk.png – Ataomega
@Ataomega Hai provato a riavviare il computer ?? Stavo avendo lo stesso problema e solo un semplice riavvio risolto. –