代码= -1005“网络连接丢失

代码= -1005“网络连接丢失

问题描述:

我的应用使用AFHTTPRequestOperationManager进行了POST请求。

am my app made and doing POST request using the AFHTTPRequestOperationManager.

我有4个网址,它们在服务器上都可以正常运行,它们的格式几乎相同,同样的用法,等等。所以我也对它们进行了相同的编码。实际上,我只有一个if语句来确定我将使用与我相同的方法使用的url,因此每次我使用POST请求任何url时,我都会使用

I have 4 urls which all works fine with the server, they are pretty much the same format, same usage, etc. So I coded them the same as well.In actually fact I only have an if statement to determine which url I shall use for the same method I made, so every time I request any of the urls with POST I use the same one.

对于其中3个它们,它们工作得很好,但是第4个,无论我如何使用,它总是让我
域= NSURLErrorDomain代码= -1005网络连接丢失。

For 3 of them they just work perfectly, but the 4th one, no matter how I use it, it always gets me "Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."

我在服务器上对该URL进行了测试,效果很好。服务器没有问题,但是AFNetworking只是不会发送此请求。如果它是真正的DC,那么我的其他URL仍然可以正常工作吗?

I tested with this url on my server, it works fine. There's nothing wrong with the server, but AFNetworking just won't send this request out. If its a true DC then my other URLs are still working fine?

我在IOS8 beta2上运行了此应用程序,我不会不知道beta是否是导致问题的原因吗(我对此表示怀疑)
请帮忙...

I run this app on IOS8 beta2, I don't know if the beta is causing the issue? (Which I doubt) pls help ...

示例代码

#define SERVER_URL  @"http://54.187.63.214/"
#define SERVER_LIKE_URL @"candidate_likeJob/"
#define SERVER_DISLIKE_URL @"candidate_dislikeJob/"

- (void) likeOrSkipJob:(BOOL)isLike{
        UserSetting *setting = [UserSetting getSetting];
        UFCompany *matchedCompany = [matchedCompanies lastObject];
        UFJob *matchJob = [matchedCompany.jobs firstObject];
        NSLog(@"like job : %@", matchJob.position);

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

        NSString *likeURL = [NSString stringWithFormat:@"%@%@",SERVER_URL,isLike? SERVER_LIKE_URL: SERVER_DISLIKE_URL];
        NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys: setting.ufind_id, @"candidate_id", matchJob.job_id, @"job_id", nil];
        NSLog(@"Request URL: %@ with params %@", likeURL, params);

        [manager POST:likeURL parameters:params success:^(AFHTTPRequestOperation *operation,  NSDictionary *response) {
            NSString *status = [response objectForKey:@"status"];

            //if server tell status ok
            if ([status isEqualToString:@"ok"]) {
                NSLog(@"%@ job success", isLike? @"Like":@"Dislike");

                //update the work if like succeed
                [matchedCompanies removeLastObject];
                [self updateMatchScreen];
            }

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"like request failed %@", error);
        }];

    }

SERVER_LIKE_URL正在生成-1005连接丢失,但是SERVER_DISLIKE_URL始终可以使用。

The SERVER_LIKE_URL is generating the -1005 "connection lost", but SERVER_DISLIKE_URL always work.

重置iOS模拟器的内容和设置,在iOS模拟器上重新编译并运行该应用程序

Reset content and setting of your iOS simulator, Recompile and run the app on iOS Simulator