I need to call the service with pass the access token in the header.
But i thing the token is not going on the header. I am not getting the responce. what am i doing wrong?
Code
+(void)getUserwithToken:(NSString *)token{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://exapmle.com/api/users"]]];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"Bearer %@", token] forHTTPHeaderField:@"Authorization"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *str1 = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",str1);
}];
}
OutPut :connectionError : (null) , str1 : {}