[英]Fetch() returns “TypeError: Network request failed” for specific URL
[英]Network request failed while fetch the data from wen URL
我是React Native的新手,從網絡URL提取數據時遇到一個常見問題。 當我運行以下代碼時,收到以下警告,但沒有數據退出。
警告:
網絡請求失敗。
編碼:
fetch('https://samples.openweathermap.org/data/2.5/forecast16?q=London&appid=b6907d289e10d714a6e88b30761fae22', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue',
})
})
另外,我嘗試了這個,但遇到了同樣的問題:
fetch('https://samples.openweathermap.org/data/2.5/forecast16?q=London&appid=b6907d289e10d714a6e88b30761fae22')
.then((response)=>response.json())
.then((resp)=> data={resp})
.catch( );
console.log("data",this.resp);
}
我應該提到我在Android上遇到這個問題。 我在這個問題上進行了大量搜索,但找不到合適的解決方案。 我還向AndroidManifest
添加了以下代碼,但問題仍然存在。
<uses-permission android:name="android.permission.INTERNET" />
我要補充的另一點是,URL是不安全的,因為在Firefox中,URL不顯示數據。
任何想法?
由於您正嘗試從SSL證書損壞的地方獲取數據,因此會收到上述錯誤消息。 頁面未通過SSL證書驗證。 您需要連接到正確配置的https頁面,或者僅使用http副本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.