Reputation: 4208
I'm using a service with REST API, which provides me an authentication token as the response for the sign in POST request.
Now for authentication on every request i need to send that token with the request. How to use this token with every request i send to server ???
Upvotes: 3
Views: 1731
Reputation: 10585
I'm not totally sure what you need from your question, but here is a guess.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://rest.u.rl/do/this"];
NSString *header = [NSString stringWithFormat:@"%@",token]; //format as needed
[request setValue:header forHTTPHeaderField:@"TokenFieldName"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPMethod: @"POST"];
And to do this for every other one, do a if (i % 2 == 0)
or something to that effect.
Upvotes: 3