|
Posted by Nosrettap |
|
|
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: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/) 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: NSURL *url = [NSURL URLWithString:SERVER_ADDRESS]; 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 [request addValue:token forHTTPHeaderField:@"X-CSRFToken"]; //Where do I get this token from NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection start]; I'm a COMPLETE newbie regarding networking (POST & GET requests...etc) and Django so any help would be very appreciated |


