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.
我正在开发一个适用于Google App Engine应用程序的iPhone应用程序。我设法通过使用谷歌帐户登录,我获得了身份验证令牌。我也能够从GAE服务中获取数据(我在阅读了这里写的另一个问题后做了)但现在我需要POST数据,所以我需要在POST请求的标题中发送身份验证令牌。我尝试了几个选项,但没有一个可行。
Here is the code I use to put that auth into the header:
这是我用来将auth放入标题的代码:
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?
3 个解决方案
#1
You need to use [request setHTTPMethod: @"POST"]
and [request setHTTPBody: postdata]
to properly configure the POST components. See the NSMutableURLRequest docs for more details.
您需要使用[request setHTTPMethod:@“POST”]和[request setHTTPBody:postdata]来正确配置POST组件。有关更多详细信息,请参阅NSMutableURLRequest文档。
#2
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.
每当我在解决与HTTP相关的问题时,我要抓的第一个工具是Charles HTTP Proxy。它将向您显示整个请求和响应,以便进一步检查。
#3
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.
如果您要对App Engine应用进行身份验证,则需要获取并发送身份验证Cookie,而不是使用GoogleLogin身份验证。 Python SDK中appengine_rpc.py的来源演示了如何。
#1
You need to use [request setHTTPMethod: @"POST"]
and [request setHTTPBody: postdata]
to properly configure the POST components. See the NSMutableURLRequest docs for more details.
您需要使用[request setHTTPMethod:@“POST”]和[request setHTTPBody:postdata]来正确配置POST组件。有关更多详细信息,请参阅NSMutableURLRequest文档。
#2
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.
每当我在解决与HTTP相关的问题时,我要抓的第一个工具是Charles HTTP Proxy。它将向您显示整个请求和响应,以便进一步检查。
#3
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.
如果您要对App Engine应用进行身份验证,则需要获取并发送身份验证Cookie,而不是使用GoogleLogin身份验证。 Python SDK中appengine_rpc.py的来源演示了如何。