You are not logged in.

Change Language:

Freelancer? Consultant? Check out: WorkTrail - Time Tracking made easy
Board » Django Standard Library » Authentication » Django in iOS

So I'm trying to POST form data to my colleague's site in order login (simple username and password) from my iPhone app. However, it appears that I need a CSRF Token in order to post. I've done a lot of research on this and from what I can obtain this token from the csrftoken cookie ( I read that here: using a GET request. The problem is, I don't know what exactly to do with this GET request? Where do I get from?

Here is the code so far for my post request:

NSData* postData= //Some form data
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"%d", postData.length] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

[request addValue:token forHTTPHeaderField:@"X-CSRFToken"]; //Where do I get this token from

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
[connection start];

I'm a COMPLETE newbie regarding networking (POST & GET requests...etc) and Django so any help would be very appreciated

Powered by Sphene Community Tools