1.出現(xiàn)unable to resolve host no address associated with hostname,這種錯(cuò)誤,一般情況下,有可能是被防火墻攔截;有可能是模擬器沒有解析域名的能力,改用IP地址;有可能是模擬器沒有獲取上網(wǎng)權(quán)限;有可能是App設(shè)置了代理,沒有連上網(wǎng)絡(luò)。
2.出現(xiàn)React Native Network Request Failed錯(cuò)誤
? ? fecth api有問題那就換用XMLHttpRequest試試看,然后控制臺(tái)輸出了the resource could not be loaded because the app transport security policy requires the use of a secure connection,百度搜索下才發(fā)現(xiàn)是iOS9引入了新特性App Transport Security (ATS)。新特性要求App內(nèi)訪問的網(wǎng)絡(luò)必須使用HTTPS協(xié)議,意思是Api接口以后必須是HTTPS。但是我的項(xiàng)目使用的是HTTP協(xié)議,現(xiàn)在也不能馬上改成HTTPS協(xié)議傳輸。
還好有替代解決方案
1. 在Info.plist中添加NSAppTransportSecurity類型Dictionary。
2. 在NSAppTransportSecurity下添加NSAllowsArbitraryLoads類型Boolean,值設(shè)為YES
這是一種情況,另外再android中
? ? ?Post數(shù)據(jù)要帶headers,里面要有Content-Type,如圖一
