0
votes

I want to Connect iOS with Drupal . I want to create node . In which i am getting session name and session id at time of login . And After I am setting on cookies . And Afterward my response is CSRF Validation Failed. I am newer in iOS. Please Help . thanks in Advance.

NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/services/node"]];

[request setHTTPMethod:@"POST"];

appDeleGate =(AppDelegate *)[[UIApplication sharedApplication]delegate];

NSLog(@"%@",appDeleGate.token);


   [request addValue:appDeleGate.token forHTTPHeaderField:@"X-CSRFToken"];
//Cookie: {session_name}={session_id}

NSString *cookie= [NSString stringWithFormat:@"{%@}={%@}",appDeleGate.session_name,appDeleGate.sessid];
NSLog(@"%@",cookie);

[request addValue:cookie forHTTPHeaderField:@"Cookie"];
//[request setValue:cookie forKey:@"Cookie"];

NSString *post =[[NSString alloc] initWithFormat:@"type=%@&title=%@",@"charity",@"aas"];

[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"%@",request);


NSURLResponse *response;
NSError *err;


NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];


if (responseData) {

    NSDictionary *loginResponseDict=[NSJSONSerialization JSONObjectWithData:responseData options:0 error:&err];
    NSLog(@"%@",loginResponseDict);


}
3

3 Answers

1
votes

I think, it could help you and save from other troubles https://github.com/kylebrowning/drupal-ios-sdk

0
votes

I don't know what kind of API you are using, the Services module or what? but anyway I can see that you made a mistake in your code

I believe it's X-CSRF-Token not X-CSRFToken

-1
votes
  1. you should log out first and then again login and then create the node.....
  2. select the ios simulator and in menubar select and reset the content and setting of simulator....
  3. option 1 is best