-1

This code works with other URL's, but not with this one. It always returns nil with "contentsOfURL". Why?

var url = NSURL(string: "http://www.bsnpr.com/api/standing.asp?serie=1&liga=1&y=2015")
var err: NSError?
var data = NSData(contentsOfURL: url!, options: nil, error: &err)

"err" delivers the message:

"Optional(Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x7f8f32c2e1e0 {NSURL=http://www.bsnpr.com/api/standing.asp?serie=1&liga=1&y=2015})"

Any ideas? Thanks in advance.

Aerofan
  • 119
  • 2
  • 5
  • 1
    See that `error` parameter? Instead of supplying `nil`, supply an instance on `NSError` - If you do this you will get error 256, which unfortunately isn't very helpful; it basically means something went wrong. It seems that `contentsOfURL` doesn't like your server for some reason – Paulw11 Jun 04 '15 at 03:09

1 Answers1

0

Your server delivers data with Transfer-Encoding set to chunked, and NSData doesn't like it.

You can get your data with a REST framework like Alamofire:

Alamofire.request(.GET, "http://www.bsnpr.com/api/standing.asp?serie=1&liga=1&y=2015")
    .responseJSON { (request, response, json, error) in
        println(json) // works with your url, I just tested
} 
Eric Aya
  • 69,473
  • 35
  • 181
  • 253