NSURLErrorDomain with code = -1100

I tried to upload a picture to my application from

enter image description here Request error with NSURLErrorDomain error and the code is really -1100. The url must be correct since I checked it in the browser. Does anyone know why?

let userImageURL: String! = "http://i.imgur.com/QhCzQoR.jpg";
let url = NSURL(fileURLWithPath: userImageURL);
let request:NSURLRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: { (response:NSURLResponse!, imageData:NSData!, error:NSError!) -> Void in
                let image = UIImage(data: imageData!);
 })
+4
source share
2 answers

The reason you get this problem is because you used

let url = NSURL(fileURLWithPath: userImageURL);

Instead, you should use:

let url = NSURL(string: userImageUrl)
+10
source

I am code in Objective-C, it is easy to convert it to Swift (a small modification actually, but the explanation is not so much related to the code). If you check the error message, you will receive:

= NSURLErrorDomain Code = -1100 " URL ." UserInfo = 0x7997b7e0 {NSErrorFailingURLStringKey = :///HTTP:/i.imgur.com/QhCzQoR.jpg, NSErrorFailingURLKey = :///HTTP:/i.imgur.com/QhCzQoR.jpg, NSLocalizedDescription = URL server., NSUnderlyingError = 0x799f3080 " URL ." }

, URL-, file:///http:/i.imgur.com/QhCzQoR.jpg, URL-. url.absoluteString, URL-, :

? fileURLWithPath: URLWithString:. :

let url = NSURL(URLWithString: userImageURL);

: URLWithString URLWithPath NSURL? doc.

+8

All Articles