“NSURLErrorDomain” - 代码:18446744073709550594 Xcode 7 上的 Ajax 调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32750601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:55:39  来源:igfitidea点击:

"NSURLErrorDomain" - code: 18446744073709550594 Ajax call on Xcode 7

iosajaxxcodexcode7nsurlerrordomain

提问by Katakam Nikhil

I am trying to make an asynchronous call from Xcode 7 as follows and I end up seeing this error "NSURLErrorDomain" - code: 18446744073709550594 This code was fine when I used it in Xcode 6. Has anybody else seen this error?

我正在尝试从 Xcode 7 进行异步调用,如下所示,我最终看到了这个错误“NSURLErrorDomain” - 代码:18446744073709550594 当我在 Xcode 6 中使用它时,这个代码很好。有没有其他人看到过这个错误?

var task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: {
            (var data, response, error) -> Void in

            if(response != nil) {
                if (isJSONP){
                    if let prefixData = "(".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
                        var prefixRange = data!.rangeOfData(prefixData,options:NSDataSearchOptions(), range: NSMakeRange(0, data!.length))
                        if let suffixData = ")".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
                            var suffixRange = data!.rangeOfData(suffixData, options: NSDataSearchOptions(), range: NSMakeRange(0, data!.length))
                            var jsonRange = NSMakeRange(prefixRange.location + 1, data!.length - prefixRange.location - 3 - suffixRange.length)
                            data = data!.subdataWithRange(jsonRange)
                            json_str = NSString(data: data!, encoding: NSUTF8StringEncoding)!
                            //     println(json_str)
                        }

                    }

                }
                do {
                    let jsonData:AnyObject? = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers)
                    callback(jsonData: jsonData)
                } catch {
                    print("JSONData not serialized properly or no data exists correctly")
                }

            }// else results not found properly/ trouble accessing server. please try again later
            else {
                var alert = UIAlertController(title: "Alert", message: "Trouble accessing server. Please try again later", preferredStyle: UIAlertControllerStyle.Alert)
                alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Default, handler: nil))
                self.presentViewController(alert, animated: true, completion: nil)
            }


        })

        task.resume()

This is the code I have used. I am neither seeing data nor a response. I tried to hit the same url using other applications and it is responding back properly. I do not see any documentation on this anywhere so posting it here. Any help would be appreciated.

这是我使用的代码。我既没有看到数据也没有看到回应。我尝试使用其他应用程序访问相同的 url,它正在正确响应。我在任何地方都没有看到有关此的任何文档,因此将其张贴在这里。任何帮助,将不胜感激。

Thank you

谢谢

Nikhil

尼基尔

采纳答案by Zeuz10

Seems to be a bug, I work around it by keeping under https all requests, hits ios9.0 and 9.0.1 as far as I can tell although you need to allow the url exception as apple documentation suggest in the Info.plist

似乎是一个错误,我通过将所有请求保持在 https 下来解决它,据我所知,命中 ios9.0 和 9.0.1,尽管您需要允许 url 异常,因为苹果文档在 Info.plist 中建议

ref. https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/

参考 https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/

回答by Katakam Nikhil

@Zeuz10 You are right. The security in ios9 and later does not allow any http calls to be sent. To get around the problem, you need to update your Info.plist The instructions are given in this link

@Zeuz10 你是对的。ios9 及更高版本中的安全性不允许发送任何 http 调用。为了解决这个问题,你需要更新你的 Info.plist 这个链接中给出了说明

http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

Thank you Zeuz10 for giving me the necessary inputs

感谢 Zeuz10 给我必要的投入

回答by sunshine

this is just -999 , you can deal it with NSURLCancel

这只是 -999 ,你可以用 NSURLCancel 处理它

回答by fagerbua

I got this exact error code when trying to connect to a server with ancient TLS support. Workaround: add NSExceptionRequiresForwardSecrecy to the app's Info.plist:

尝试连接到具有古老 TLS 支持的服务器时,我得到了这个确切的错误代码。解决方法:将 NSExceptionRequiresForwardSecrecy 添加到应用程序的 Info.plist:

<key>NSExceptionDomains</key> 
<dict>
  <key>MY_SERVER_DOMAIN</key>
  <dict>
    <key>NSExceptionRequiresForwardSecrecy</key>
    <false/>
  </dict>
  <!-- any other exceptions you may have -->
</dict>