![](/img/trans.png)
[英]Http GET Request from NodeJS to external API with http.get()
[英]$http.get request does not work with API level 31
我請求你的幫助解決我在使用 IONIC 1 時遇到的問題。當我在 config.xml 文件中將 API 級別從 30 更改為 31 時:
此代碼無效
$http.get($scope.url)
.then(function (success) {
...
}, function (error) {
$scope.errTXT = JSON.stringify(error);
});
返回狀態 0。
{“數據”:null,“狀態”:0,“配置”:{“方法”:“GET”,“transformRequest”:[null],“transformResponse”:[null],“url”:“https:/ /xxxxxxxxxxxxxxxxxx", headers: { "Accept": "application/json, text/plain, / " } }, "statusText": "" }
不明白為什么http的結果是null
僅供參考,當我改回 API 30 時,一切正常。 我不認為是服務器問題。 我開始認為 API 不支持 $http.get 31? 我的服務器運行在 HTTPS://......
Ionic CLI : 5.4.16 (C:xxxxxxxx\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic1 1.3.1
@ionic/v1-toolkit : not installed
Cordova:
Cordova CLI : 11.0.0
Cordova Platforms : android 9.1.0
Cordova Plugins : cordova-plugin-ionic-webview 1.2.1, (and 16 other plugins)
Utility:
cordova-res : not installed
native-run : not installed
System:
Android SDK Tools : 26.1.1 (xxxxxxxx
\AppData\Local\Android\Sdk\)
NodeJS : v14.16.1 (C:\Program Files\nodejs\node.exe)
npm : 7.24.2
OS : Windows 10
您是否刪除了“android”文件夾並重新添加?
ionic cordova platform remove android
ionic cordova platform add android
狀態代碼 0 通常表示 CORS 錯誤。
您可以在此處閱讀有關 Ionic CORS 錯誤的信息。
從本質上講,這可能是您的服務器標頭配置錯誤導致您的 Android 應用程序拋出狀態代碼 0。
如果您使用的是開發環境(例如localhost:4200
),那么您可以將以下內容添加到您的config.xml
中,這樣您就可以在不需要 HTTPS 的情況下運行它:
<preference name="hostname" value="localhost" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.