views:

849

answers:

4

I'm working on an IPhone application that works with a Google App Engine application. I manage to get logged by using a google account and I get the authentication token. I'm also able to GET data from the GAE service (I did it after reading another question written here) but now I need to POST data so I need to send the authentication token in the header of the POST request. I tried several options but none of them worked.

Here is the code I use to put that auth into the header:

NSString* urlStr = [NSString stringWithFormat:@"%@%@", HOST, url];
NSMutableURLRequest* urlPost = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr]]; 
NSString* authStr = [NSString stringWithFormat:@"GoogleLogin auth=%@", token];
[urlPost addValue:authStr forHTTPHeaderField:@"Authorization"];

but it doesn't work.

Any help?

+2  A: 

Whenever I'm troubleshooting a problem related to HTTP, the first tool I'll grab is Charles HTTP Proxy. It will show you the entire request and response for closer examination.

Marc Novakowski
+3  A: 

You need to use [request setHTTPMethod: @"POST"] and [request setHTTPBody: postdata] to properly configure the POST components. See the NSMutableURLRequest docs for more details.

Ben Gottlieb
Yes, I had used that method to POST the data.IMPORTANT: Actually the request goes to the server but... the user information is not sent. My server code first checks the user and then executes the business logic but it fails because no user is returning from users.get_current_user() method
+1  A: 

If you're authenticating against an App Engine app, you need to obtain and send an authentication cookie, rather than using the GoogleLogin authentication. The source of appengine_rpc.py in the Python SDK demonstrates how.

Nick Johnson
A: 

You said you managed 'to get logged by using a google account and I get the authentication token'... How do you did that?

remyvhw