ios - How to send a token from the iphone to rails backend? -


when i'm asking backend token username + password, returns:

{"token":"5kb2bthsslgbezjmqvfa"} 

this have working far. token, saved.

- (void)requestfinished:(asihttprequest *)request {     if ([request responsestatuscode] != 200) {         [self requestfailed:request];     }     else {         nslog(@"%@", [request responsestring]);         nsdata * data = [request responsedata];         nsdictionary *token = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves error: nil];          // authentication successful, store token         nsuserdefaults* defaults = [nsuserdefaults standarduserdefaults];         [defaults setvalue:[token objectforkey:@"token"] forkey:@"auth_token"];     } } 

now want send token every next request, don't know how. can tell me what's missing?

nsurl *url = [nsurl urlwithstring:@"http://localhost:3000/userdetails"];     asihttprequest *request = [asihttprequest requestwithurl:url]; [request setdelegate:self];  // auth token? [request startasynchronous]; 

asi don't have special fields "auth token". if want add field request can by:

  1. add post/get attribute
  2. add header value addrequestheader:value:

if want pass every request can consider creating "api manager" or "authentication manager" singleton class.

or maybe may change http authentication: http://allseeing-i.com/asihttprequest/how-to-use#handling_http_authentication

i consider using cookies - if backend has possibility return whole cookie object instead of token. asi handle session cookies.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -