失败:错误域=NSURLErrorDomain 代码=

编程入门 行业动态 更新时间:2024-10-26 22:25:21
本文介绍了失败:错误域=NSURLErrorDomain 代码=-1004“无法连接到服务器".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在此之前,我想列出我已阅读并尝试实现答案的帖子(避免重复):

Before anything, I want to list out the posts that I have read and tried implementing the answers from (avoiding duplicates):

  • iOS 9 和 iOS 中的应用传输安全问题10
  • iosdevtips.co/post/121756573323/ios-9-xcode-7-http-connect-server-error
  • www.neglectedpotential/2015/06/working-with-apples-application-transport-security/

我正在开发一个 SDK,我已经创建了一些 UI 测试.我试图不连接到后端系统并通过在测试时在本地机器上运行的存根服务器模拟它们.所有请求都必须发送到此服务器.

I am working on an SDK and I have created some UI tests. I am trying not to connect to the backend systems and mocking them via a stubserver that runs in the local machine whilst testing. All requests must go to this server.

我创建了一个永远不会提交到 App Store 的虚拟应用程序.通过这个应用程序,我计划测试 SDK 的屏幕.我遵循了上面的帖子和文章,并在虚拟应用程序的 Info.plist 文件中包含了一个异常,即与我的本地主机服务器的不安全连接.如下所示:

I have created an dummy app that will never be submitted to the App Store. Through this app I plan to test the SDK's screens. I followed the posts and articles above and included an exception to have insecure connections to my localhost server into the dummy app's Info.plist file. It looks like the following:

<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>localhost</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> </dict> </dict> <key>NSAllowsArbitraryLoadsInWebContent</key> <true/> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

是的,我允许各种例外.网络响应不会抱怨应用程序没有与 localhost 的不安全连接的异常,而是简单地返回以下内容:

Yes I have allowed all kinds of exceptions. The network response does not complain about the app not having the exception for insecure connections to localhost but simply returns the following:

[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x170248940 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=localhost:7878/endpoint, NSErrorFailingURLKey=localhost:7878/endpoint, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.} [Timeline]: Timeline: { "Request Start Time": 510144201.835, "Initial Response Time": 510144201.860, "Request Completed Time": 510144201.860, "Serialization Completed Time": 510144201.860, "Latency": 0.025 secs, "Request Duration": 0.025 secs, "Serialization Duration": 0.000 secs, "Total Duration": 0.025 secs }

我查看了服务器日志,没有任何报告.因此,我假设它不会完全命中服务器.

I look at the server logs and nothing is reported. I therefore assume that it does not hit the server entirely.

任何帮助将不胜感激.:)

Any help would be appreciated. :)

谢谢

推荐答案

正如@Teffi 在评论中指出的那样,我在无法访问本地计算机上运行的 localhost 服务器的设备上运行测试.

As @Teffi pointed out in the comments I was running the test on a device that did not have access to my localhost server running on my local machine.

更多推荐

失败:错误域=NSURLErrorDomain 代码=

本文发布于:2023-11-26 05:43:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   代码   NSURLErrorDomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!