NSURLErrorDomain Code=-1012 The operation couldn’t be completed

ぐ巨炮叔叔 提交于 2019-12-10 14:37:57

问题


I am getting the following error when running my code from the xcode.

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x17166b740 {NSErrorFailingURLStringKey=https://..../move/resource/v1/user/me/activity/summary?start_date=2015-01-21&end_date=2015-01-14&detail=true, NSUnderlyingError=0x17405b630 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)", NSErrorFailingURLKey=https://..../move/resource/v1/user/me/activity/summary?start_date=2015-01-21&end_date=2015-01-14&detail=true}

Here is my Code

  NSString *urlSummaryString = [[NSString stringWithFormat: @"%@summary?start_date=%@&end_date=%@&detail=true", kMisfitCloudEndpoint, strStartDate,strEndDate] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    __block NSMutableDictionary *responseDict = [NSMutableDictionary dictionary];
    __block NSError *error = nil;
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlSummaryString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
    [request setValue:@"access_token" forHTTPHeaderField:self.misfitAccessToken];
    [request setHTTPMethod:@"GET"];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if(connectionError){
            // Handle the connection error
            return ;
        }}];

Can any one help me what is wrong here. Is it something related to SSL Certificate on the server and is related to the security. When I use CocoaRestClient to make my request it works perfectly.

Can some body explain me in detail what cause this problem or if any body can have the solution for this. I have to use [NSURLConnection sendAsynchronousRequest] method. I am using Xcode 6.1 and ios 8.1.2


回答1:


In my case i am making a very silly mistake.

[request setValue:self.misfitAccessToken forHTTPHeaderField:@"access_token" ];

This solved my problem




回答2:


This is kCFURLErrorUserCancelledAuthentication error, -10xx errors are of the CFNetworkErrors enum. Name of this constant is pretty selfexplanatory. Server cancelled authentication for some reason



来源:https://stackoverflow.com/questions/28069651/nsurlerrordomain-code-1012-the-operation-couldn-t-be-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!