网络连接已丢失.NSURLErrorDomain代码= -1005

时间:2015-05-15 14:43:31

标签: ios objective-c ios8 afnetworking

有人可以提供帮助吗?。我在我的应用程序中使用AFNetworking(1.x)POST方法。但我经常得到:

  

'网络连接丢失'error.Error Domain = NSURLErrorDomain Code = -1005“网络连接丢失。”

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFHTTPResponseSerializer serializer];
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
op.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    [self SuccessResponse:responseObject:reqType];
    NSLog(@"JSON responseObject: %@ ",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];

1 个答案:

答案 0 :(得分:0)

确保您的网络连接正常。

尝试使用以下代码。

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];

NSDictionary *params ; // Pass your POST Parameters here by creating the Dictionary.

[manager POST:@"your api here" parameters:params success:^(AFHTTPRequestOperation *operation,  id responseObject) {
          // Success 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        // Request failed
        // To get failed response data use operation.responseObject
        NSLog(@"like request failed %@", error);
}];

希望这会对你有所帮助。