linux – IBM Swift Sandbox:运行NSURLSession:运行代码时出错
发布时间:2020-12-14 00:31:53 所属栏目:Linux 来源:网络整理
导读:我正在尝试执行以下脚本: import Foundationclass TestURLSession{var session: NSURLSession!func run(){ session = NSURLSession.sharedSession() let url = NSURL(string: "http://www.veenex.de/tmp/json") let request = NSMutableURLRequest(URL: url
我正在尝试执行以下脚本:
import Foundation class TestURLSession{ var session: NSURLSession! func run(){ session = NSURLSession.sharedSession() let url = NSURL(string: "http://www.veenex.de/tmp/json") let request = NSMutableURLRequest(URL: url!) request.setValue("application/json; charset=utf-8",forHTTPHeaderField: "Content-Type") request.HTTPMethod = "GET" let getDataTask = session.dataTaskWithRequest(request,completionHandler: {(data,response,error) in // HTTP Response contains an error if let httpResponse = response as? NSHTTPURLResponse { if httpResponse.statusCode != 200 { print("response was not 200: (response)") return } } // Error submitting Request if error != nil { print("error submitting request: (error)") return } // print data if data != nil{ do { let json = try NSJSONSerialization.JSONObjectWithData(data!,options: NSJSONReadingOptions.MutableContainers) as! NSArray for entry in json { print(entry) } } catch { print("Error printing data") } } }); getDataTask.resume() } } let testURLSession = TestURLSession() testURLSession.run() 但是我收到错误消息:“运行代码时出错:未知错误代码132”. 解决方法
尚未编写NSURLSession的纯Swift实现.查看Apple的GitHub repo for Foundation上的
NSURLSession.swift 文件.
每个方法都是NSUnimplemented(),这意味着它尚未实现.在此类完成之前,它将无法在Linux和IBM的Swift Sandbox上使用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |