【问题标题】:The network connection was lost.NSURLErrorDomain Code=-1005网络连接丢失。NSURLErrorDomain Code=-1005
【发布时间】:2015-07-27 13:11:03
【问题描述】:

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

'网络连接丢失'错误。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) {
}];

【问题讨论】:

标签: ios objective-c ios8 afnetworking


【解决方案1】:

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

尝试使用下面的代码。

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

希望这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 2019-10-12
    • 2023-03-10
    • 2016-02-22
    • 2014-09-03
    • 2017-03-08
    • 2017-11-06
    • 2014-10-11
    • 2017-05-07
    • 1970-01-01
    相关资源
    最近更新 更多