0

I am trying to use NSURLSession, I had successfully received token from server, now I have to used that Token to get further details... I had tried below code to get user data.. but I am getting httpResponse code: 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];

I am using iOS 10 , above code is not working, also I have tried several ways but no any success...

I have tried stackoverflow solution but this is also not working out for me... Please help me out...

Community
  • 1
  • 1
user2813740
  • 517
  • 1
  • 7
  • 29
  • Is the server crashing? A 500 http response usually indicates that. – Sealos Oct 06 '16 at 13:30
  • is my request is correct...as i read request may not be sending in correct format to server – user2813740 Oct 06 '16 at 13:31
  • my 1st request to get token works fine..from same server... i am sending username & password...to authanticate my app and saves token send back from server... – user2813740 Oct 06 '16 at 13:33
  • Yes, but the server is crashing. Error 500 means that the server had an internal error. – Sealos Oct 06 '16 at 13:33
  • something of what you are sending is making the server fail. A good server api should tell you why your request fails, you can debug data and error returned and see if that leads to the cause. – Christian Oct 06 '16 at 13:34
  • do i have to send encoded data ...token i am sending ...is it required to encode or some thing ? or else how i can check from server side ...why it is crashing.... – user2813740 Oct 06 '16 at 13:38
  • httpResponse head: { "Cache-Control" = "no-cache"; "Content-Length" = 36; "Content-Type" = "application/json; charset=utf-8"; Date = "Thu, 06 Oct 2016 12:16:58 GMT"; Expires = "-1"; Pragma = "no-cache"; Server = "Microsoft-IIS/8.5"; "X-AspNet-Version" = "4.0.30319"; "X-Powered-By" = "ASP.NET"; } – user2813740 Oct 06 '16 at 13:39
  • httpResponse code: 500 – user2813740 Oct 06 '16 at 13:39
  • i am getting above response – user2813740 Oct 06 '16 at 13:39
  • Request a server fix. – Sealos Oct 06 '16 at 13:43

0 Answers0