ios - What am I doing wrong with this AFNetworking JSON Post? -


i have odd problem... i'm doing ios http/json post using afnetworking against rails server , expected output like:

{"success":true,"auth_token":"4d8cyusygzdqo6x1tceq"} 

sometimes works expected, on rails side request not detected "json" request serves html. have idea on this? there i'm doing wrong regards setting json request?

 nsdictionary *parameter = @{@"email":@"philswenson@mymail.com", @"password":@"mypassword"};     afhttpclient *httpclient = [[afhttpclient alloc] initwithbaseurl:[nsurl urlwithstring:@"http://localhost:3000"]];     [httpclient setparameterencoding:afjsonparameterencoding];     [httpclient registerhttpoperationclass:[afjsonrequestoperation class]];      [httpclient postpath:@"api/v1/sessions" parameters:parameter success:^(afhttprequestoperation *operation, id responseobject) {          nsstring *jsonstring = [[nsstring alloc] initwithdata:responseobject encoding:nsutf8stringencoding];          nslog(@"here got %@", jsonstring);         nsdictionary *loginresult = [jsonstring objectfromjsonstring];         nsnumber* success = [loginresult objectforkey:@"success"];         nslog(@"success = %@", success);         nslog(@"yay");         // sample output:         //  {"success":true,"auth_token":"4d8cyusygzdqo6x1tceq"}      } failure:^(afhttprequestoperation *operation, nserror *error) {         [self handleconnectionerror:error];     }]; 

i know service, need add application/jsonrequest accept parameters this:

nsdictionary *parameter = @{@"email":@"philswenson@mymail.com", @"password":@"mypassword", @"accept:application/jsonrequest"}; 

the afjsonparameterencoding tells send parameters in json file. need send parameter tell how send data back.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -