ios - setting a request header for an authorization token in afnetworking -


i want add authorization token header of request(within request want json information server) here code:

afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; manager.requestserializer = [afjsonrequestserializer serializer]; //[manager.requestserializer setauthorizationheaderfieldwithtoken:token]; [manager.requestserializer setvalue:@"application/json" forhttpheaderfield:@"accept"]; [manager.requestserializer setvalue:@"application/json" forhttpheaderfield:@"content-type"]; [manager.requestserializer setvalue:@"4959a0bc00a15e335fb6" forhttpheaderfield:@"authorization"]; [manager get:@"http://domain.com/recipes.json" parameters:nil success:^(afhttprequestoperation *operation, id responseobject) {     nslog(@"json: %@", responseobject);     nserror *e=nil;      recipesarray = [nsjsonserialization jsonobjectwithdata:responseobject options:nsjsonreadingmutablecontainers error:&e]; } failure:^(afhttprequestoperation *operation, nserror *error) {     nslog(@"error: %@", error); }]; 

i got error: operation couldn’t completed. (cocoa error 3840.)" (json text did not start array or object , option allow fragments not set.) userinfo=0x7f8098529760 {nsdebugdescription=json text did not start array or object , option allow fragments not set., nsunderlyingerror=0x7f8098513790 "request failed: unauthorized (401)"}

does know reason? lot

you don't need afjsonrequestserializer need afjsonresponseserializer

request => response

and afjsonresponseserializer default responseserializer don't change requestserializer


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -