繁体   English   中英

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

[英]The network connection was lost.NSURLErrorDomain Code=-1005

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

“网络连接丢失”错误。错误域= NSURLErrorDomain代码= -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) {
}];

确保您的互联网连接正常。

尝试使用下面的代码。

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);
}];

希望这会帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM