Afnetworking: How to get " responseObject" use "NSURLSessionDataTask *task"

Created on 4 Aug 2016  路  3Comments  路  Source: AFNetworking/AFNetworking

failure:^(NSURLSessionDataTask *task, NSError *error) {
// responseString or responseObject?
}]

Most helpful comment

If you want the raw data, you can use AFNetworkingOperationFailingURLResponseDataErrorKey as above.

All 3 comments

The responseObject should be something like NSData or JSON object based on responseSerializer you are using. However, nothing would actually returns if your request failed. Thus you cannot cate responseObject in failure handler.

This problem has been solved:
failure:^(NSURLSessionDataTask *task, NSError *error) {
NSData *responseData = (NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
}]

If you want the raw data, you can use AFNetworkingOperationFailingURLResponseDataErrorKey as above.

Was this page helpful?
0 / 5 - 0 ratings