简体   繁体   English

来自 Capacitor App 的 iOS 模拟器网络错误

[英]Network Error on iOS emulator from Capacitor App

I am using Angular Capacitor v3 with axios.我正在使用带有 axios 的 Angular Capacitor v3。 Receiving a Network Error when making any request to any external server.向任何外部服务器发出任何请求时收到网络错误。 This is only occurring while emulating with XCode.这仅在使用 XCode 进行仿真时发生。 The request never reaches the server, just returns immediately with status 0.请求永远不会到达服务器,只是立即以状态 0 返回。

I cannot repeat this problem locally on Windows, or published website, or Android Studio emulators, or published to android device.我无法在 Windows、已发布的网站、Android Studio 模拟器或发布到 android 设备上本地重复此问题。

Not sure if I am missing a permission or configuration, but I have tried adding "Local Network Usage", "Location Always and When In Use" permissions and played around with NSAppTransportSecurity settings to the Info.plist.不确定我是否缺少权限或配置,但我尝试添加“本地网络使用情况”、“始终使用位置和使用时位置”权限,并在 Info.plist 中使用 NSAppTransportSecurity 设置。

I do not believe its an issue with the server since it seems like it never even reaches it.我不相信这是服务器的问题,因为它似乎从未到达过它。 But I have a verified HTTPS certificate, hosted by Azure, with valid CORS rules.但我有一个经过验证的 HTTPS 证书,由 Azure 托管,具有有效的 CORS 规则。

I have also tried HttpClient with Angular, same result.我也尝试过使用 Angular 的 HttpClient,结果相同。

The error occurs immediately and does not give specific information but here is the message:错误立即发生并且没有提供具体信息,但这里是消息:

{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":"https://jsonplaceholder.typicode.com/users/1","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://jsonplaceholder.typicode.com/users/1 : 0 Unknown Error","error":{"isTrusted":true}} {"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"未知错误","url":"https:/ /jsonplaceholder.typicode.com/users/1","ok":false,"name":"HttpErrorResponse","message":"Http失败响应https://jsonplaceholder.typicode.com/users/1 :0未知错误","error":{"isTrusted":true}}

I am just facing same issue It was working on different domain, no hostname is different and it stopped working.我只是面临同样的问题它在不同的域上工作,没有主机名不同,它停止工作。 So it doesn't even make a request to a server.所以它甚至不会向服务器发出请求。 Also same configuration works on android.同样的配置也适用于 android。 just not IOS只是不是IOS

After extensive research and rebuilding from scratch, I found this was a CORS related issue but specific to setup with Azure, which was my hosted server.经过广泛的研究和从头开始重建,我发现这是一个与 CORS 相关的问题,但特定于使用 Azure 进行设置,这是我的托管服务器。 The confusing part was that even external example calls, such as to "http://jsonplaceholder.typicode.com/users/1" still gave the same error, which wouldn't have CORS issues, as far as I understand.令人困惑的部分是,即使是外部示例调用,例如“http://jsonplaceholder.typicode.com/users/1”仍然给出相同的错误,据我所知,不会有 CORS 问题。 If anyone knows why that happens, please let me know.如果有人知道为什么会这样,请告诉我。

This was related to the fact that in ios, the http/https schemes cannot be used, instead it uses capacitor .这与在 ios 中不能使用 http/https 方案,而是使用capacitor This scheme is not allowed in Azure App Service CORS settings, unless you allow all, but I could not because I needed to enable Access-Control-Allow-Credentials. Azure 应用服务 CORS 设置中不允许使用此方案,除非您允许所有,但我不能,因为我需要启用 Access-Control-Allow-Credentials。 So I had to build the CORS configuration with the capacitor scheme allowed in my C# app service code.因此,我必须使用 C# 应用程序服务代码中允许的capacitor方案构建 CORS 配置。 Removing all settings from CORS in Azure App Service then allowed the settings in my C# code to be applied.从 Azure 应用服务中的 CORS 中删除所有设置,然后允许应用我的 C# 代码中的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ionic 4 在 iOS 设备上运行应用程序时出现电容器错误 - Ionic 4 running app on iOS device error with capacitor 带有 Iframe 的电容器应用程序无法在 IOS 上运行 - Capacitor app with Iframe not working on IOS 从 Capacitor 获取 IOS 控制台 - Getting IOS console from Capacitor Angularfire 不适用于 ios 上的离子电容器应用程序 - Angularfire does not work on ionic capacitor app on ios 为什么在 iOS 上运行的空白离子电容器应用程序返回此错误:无法连接到服务器 - Why blank Ionic capacitor App running on iOS return this Error: Could not connect to the server 尝试在iOS设备上运行应用程序时出错。 它在模拟器上运行 - Error trying to run app on iOS device. It runs on emulator 从 React Native iOS 应用程序查询 Flask 资源时出现 Axios.network 错误(无效的 imageTag) - Axios network error (Invalid imageTag) when querying a Flask resource from React Native iOS app Firebase Facebook从iOS模拟器中的Ionic(Cordova)应用程序登录 - Firebase Facebook Login from Ionic (Cordova) app in iOS Emulator 使用 Capacitor 为 iOS 构建时,Phaser 3 应用程序中没有声音 - No sound in Phaser 3 app when using Capacitor to build for iOS 离子/电容器反应应用程序 API 请求在 iOS 上返回 HTML - Ionic/Capacitor React App API Requests returning HTML on iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM