NSURLSession将令牌发送回不与ios10一起使用的服务器

时间:2016-10-06 13:29:08

标签: ios objective-c nsurlsession

我正在尝试使用NSURLSession,我已成功从服务器接收令牌,现在我必须使用该令牌获取更多详细信息... 我试过下面的代码来获取用户数据.. 但我得到httpResponse代码:500

 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

        NSString *authValue = [arrTokenData valueForKey:@"Token"];

        //Configure session with common header fields
        NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
        sessionConfiguration.HTTPAdditionalHeaders = @{@"bearer": authValue};

        NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

        NSString *url = @"http://test.myserver.am/api/mobile/LookUps/getuserdata";
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];

        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
            if (!error) {
                NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
                if (httpResponse.statusCode == 200)
                {
                    NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:nil];

                    //Process the data
                }
            }

        }];
        [task resume];

我使用的是iOS 10,上面的代码不能正常工作,我也尝试了几种方法,但没有任何成功......

我试过stackoverflow solution,但这对我来说也没有用... 请帮帮我...

0 个答案:

没有答案