简体   繁体   English

NSURLSession数据始终为零字节

[英]NSURLSession data always zero bytes

I swear it was working the other day and now I get data as zero bytes in the response back. 我发誓前几天它在工作,现在我在响应中得到的数据为零字节。 The result variable is empty. 结果变量为空。 Am I being blocked by Flickr API? 我被Flickr API阻止了吗?

Here is my code: 这是我的代码:

func setup() {

    let flickrURL = "http://api.flickr.com/services/feeds/photos_public.gne?tags=texas&tagmode=any&format=json&jsoncallback=?"

    let session = NSURLSession.sharedSession()

    (session.dataTaskWithURL(NSURL(string :flickrURL)!, completionHandler: { (data :NSData!, response, error) -> Void in

        let result = NSString(data: data, encoding: NSUTF8StringEncoding)

        // convert result into JSON dictionary 
      //  NSJSONSerialization.JSONObjectWithData(data, options:nil, error: nil) as NSDictionary

        println("\(result!)")



    })).resume()

}

Here is what is stored in the error parameter: 以下是错误参数中存储的内容:

Printing description of error.Some:
Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x7fde2da8f390 {NSErrorFailingURLStringKey=http://api.flickr.com/services/feeds/photos_public.gne?tags=texas&tagmode=any&format=json&jsoncallback=?, NSErrorFailingURLKey=http://api.flickr.com/services/feeds/photos_public.gne?tags=texas&tagmode=any&format=json&jsoncallback=?, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x7fde2da63430 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}

重新启动模拟器应该可以解决此问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM