[Solved] iOS – NSURLConnection finished with error – code -1002

The network request will be abnormal, for example reporting an error: Error domain: @"NSURLErrorDomain" - code: 1002

Hit a breakpoint at the callback, and then use the command line to see what the error is: po error
When the error is: **[Error Domain=NSURLErrorDomain Code=-1002 ] "unsupported URL" **
*Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSUnderlyingError= 0x7fa9b1d06120 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}} * when the URL encoding problem, deal with the URL encoding will be fine

My side is the backend returned spliced interface more "/", resulting in a unified domain name format is not uniform
Processing:


iOS 8 To use utf8 transcoding.

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];


For iOS 8 onwards, use this method: [urlString

urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"#%^{}\"[]|\\<> "].invertedSet];

Similar Posts: