为什么NSURLConnection会生成此错误NSPOSIXErrorDomain“操作已取消"? [英] Why would an NSURLConnection generate this error, NSPOSIXErrorDomain "Operation Cancelled"?

查看:66
本文介绍了为什么NSURLConnection会生成此错误NSPOSIXErrorDomain“操作已取消"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 9中,我将NSURL与NSURLConnection一起使用,并且对于一个特定的URL,它在- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error委托方法中生成了以下错误.

In iOS 9, I'm using NSURL with NSURLConnection and for one specific URL, it's generating the following error in the - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error delegate method.

错误域= NSPOSIXErrorDomain代码= 89操作已取消" UserInfo = {NSErrorFailingURLStringKey = URL,_kCFStreamErrorDomainKey = 1, NSErrorPeerAddressKey = {长度= 16 容量= 16,字节= 0x100201bb41d733370000000000000000}, _kCFStreamErrorCodeKey = 89,NSErrorFailingURLKey = URL}

Error Domain=NSPOSIXErrorDomain Code=89 "Operation canceled" UserInfo={NSErrorFailingURLStringKey=URL, _kCFStreamErrorDomainKey=1, NSErrorPeerAddressKey={length = 16, capacity = 16, bytes = 0x100201bb41d733370000000000000000}, _kCFStreamErrorCodeKey=89, NSErrorFailingURLKey=URL}

该请求不会被取消,至少不会被我们的代码取消.奇怪的是,这里的错误甚至不是NSURLErrorDomain,而是NSPosixErrorDomain.

The request isn't being canceled, at least not by our code. What's strange is that the error here isn't even NSURLErrorDomain, it's NSPosixErrorDomain.

该领域的用户报告了一个问题,这是根本原因,但是很难确定确切原因.在OS X上使用curl访问此特定URL(使用相同的请求,User-Agent和所有请求),不会产生此错误,响应完全符合预期.但是,即使从iOS Safari浏览器访问此特定的URL仍然不起作用.可能有一些奇怪的服务器配置,但我不希望该错误如此普遍,如被取消.

A user in the field reported an issue and this is the root cause, but it's tough to determine exactly why this is happening. Accessing this specific URL with curl on OS X(using the same request, User-Agent and all), doesn't produce this error, the response is completely as expected. However, even accessing this specific URL from the iOS Safari browser still doesn't work. It's possible there is some strange server configuration, but I wouldn't expect the error to be so general like canceled.

也有报道称,iOS 8并没有发生这种情况.此URL并没有什么异常之处,似乎它无法通过我们的堆栈.除了didFailWithError之外,没有身份验证挑战或任何类型的委托回调发生,它会立即发生.还有其他人在iOS 9中看到过这种行为吗?

It's also been reported that this wasn't occurring with iOS 8. There's nothing out of the ordinary about this URL, it just seems it can't pass through our stack. No auth challenges or any kind of delegate callbacks occur, except for didFailWithError and it occurs immediately. Anyone else seen this kind of behavior in iOS 9?

更新:似乎会产生此错误的特定URL不仅限于我们的应用程序.实际上,仅尝试在iOS 9的iOS Safari中访问此特定URL会产生相同的错误.我设法在iOS Safari的iOS 8.3上对此进行了测试,但未重现该错误.

Update: The particular URL that seems to produce this error is NOT limited to our apps alone. In fact, simply trying to access this particular URL in iOS Safari on iOS 9 produces the same error. I managed to test this on iOS 8.3 in iOS Safari and the error was not reproduced.

推荐答案

这可能是ATS问题吗?对于与iOS 9 SDK链接的应用程序,iOS 9使用更严格的规则来规定它将接受哪种类型的TLS证书,以及它将允许哪种TLS协议(例如,不再使用SSLv3).此外,它要求所有请求均为HTTPS(而非HTTP).

Could this be an ATS issue? For apps linked against the iOS 9 SDK, iOS 9 uses stricter rules for what types of TLS certs it will accept, and for what TLS protocols it will allow (e.g. no more SSLv3). Additionally, it requires that all requests be HTTPS (not HTTP).

您可以覆盖此行为(如果必须)或修复服务器.

You can either override this behavior (if you must) or fix the server.

有关详细信息,请参阅Apple的

For details, see Apple's Info.plist documentation.

如果这样做没有帮助,请尝试按 QA 1887 ,看看它吐出了什么.

If that doesn't help, try enabling CFNetwork debugging as described in QA 1887 and see what it spits out.

这篇关于为什么NSURLConnection会生成此错误NSPOSIXErrorDomain“操作已取消"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆