React Native kullanarak basit bir uygulama geliştiriyorum. Android cihazında test ediyorum. İstekleri dinlemek için bir Node.js sunucusu oluşturdum, http://localhost:3333/ adresinde çalışıyor. Sonraki, index.android.js adresinden bir istek isteği yapıyorum. Kod aşağıdadır.React Native: Getirme isteği hatayla başarısız oldu - TypeError: Ağ isteği başarısız oldu (…)
fetch('http://localhost:3333/',
{
'method': 'GET',
'headers': {
'Accept': 'text/plain',
}
}
)
.then((response) => response.text())
.then((responseText) => {
console.log(responseText);
})
.catch((error) => {
console.warn(error);
});
düğüm sunucuda istek işleyicisi için kod yakalama isteği çalışmıyor, aşağıda
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(express.static('public'));
app.get('/', function(req, res){
console.log('Request received for /');
res.send("this is the response from the server");
res.end();
});
olduğunu ama. Chrome konsolunda aldığım hata: TypeError: Ağ isteği başarısız oldu (…).
Bu iş nasıl yapılır?
Teşekkür cihaz bağlantı noktası 8081 yönlendirir! İşe yaradı. – Chetan
URL'ye çağrı yapıyorum ama yine de aynı hatayı alıyorum. getirme ('http://private-18642-test2979.apiary-mock.com/notes/1', { yöntemi: { 'Kabul: 'başlıklar',' elde 'uygulama/json' , } –
Bu gerçekten bir URL değildir, protokolü de eklemeniz gerekir – oblador