I have a rest web service request to be called in Objective C. How to add token to web service request for authentication ??
Thanks in advance
Add token in request as below
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:yourURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"GET"]; // Set your method
[request addValue:@"token_value" forHTTPHeaderField:@"Authorization"];
// ...... your code
// ........ add data
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//HideProcess;
if (error)
{
//NSLog(@"Error : %@\n", error);
return;
}
if (data != nil)
{
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
NSLog(@"Response :\n%@\n", dict);
}
}];
[task resume];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.