AFNetWorking 请求失败
AFNetWorking请求失败返回NSError分析,下面的方法是直接调用manager的post请求
- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
parameters:(nullable id)parameters
progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
在failure的block里打印error.userInfo和其keys
NSLog(@"***userInfo***:%@", error.userInfo);
NSLog(@"***userInfo.allKeys***:%@", error.userInfo.allKeys);
2016-08-08 10:05:33.173 jmsfhz_ios[11475:4109574] ***userInfo.allKeys***:(
NSDebugDescription,
NSUnderlyingError
)
NSDebugDescription:该错误的描述
NSUnderlyingError:更加底层的错误,用字典方式取出后仍是一个NSError
下面再次打印这个底层error的userInfo的keys
NSLog(@"***underError.userInfo.allKeys***:%@", underError.userInfo.allKeys);
2016-08-08 10:05:33.194 jmsfhz_ios[11475:4109574] ***underError.userInfo.allKeys***:(
"com.alamofire.serialization.response.error.response",
NSErrorFailingURLKey,
"com.alamofire.serialization.response.error.data",
NSLocalizedDescription
)
"com.alamofire.serialization.response.error.response"
:一个响应体数据
NSErrorFailingURLKey
:失败的请求地址
"com.alamofire.serialization.response.error.data"
:失败获取的数据,NSData类型,可以转化为字符串,获得它的描述
NSLocalizedDescription
:错误描述
网友评论