【发布时间】:2011-12-07 06:18:20
【问题描述】:
我现在遇到了谷歌应用引擎最奇怪的问题。我从 iOS 发送一个 POST 请求,而谷歌应用引擎调用了 GET 处理程序。
我已将这种情况沙盒化以进行测试,但无法弄清楚。我有一个只发送请求的 iOS 应用程序。除了服务之外,我已经评论了 GAE 上的所有内容。该服务只记录一个参数并返回。
我尝试过使用两种不同方式发送请求的 iOS 应用。两者都不起作用。
iOS 代码:
/*
NSURL * url = [NSURL URLWithString:@"http://beermonster-gngrwzrd.appspot.com/TestParameter"];
ASIFormDataRequest * _fdrequest = [[ASIFormDataRequest alloc] initWithURL:url];
[_fdrequest setPostValue:@"hello" forKey:@"testkey"];
[_fdrequest startAsynchronous];
*/
NSURL * __url = [NSURL URLWithString:@"http://beermonster-gngrwzrd.appspot.com/TestParameter"];
NSMutableURLRequest * __request = [NSMutableURLRequest requestWithURL:__url];
[__request setHTTPMethod:@"POST"];
NSString * post = [NSString stringWithFormat:@"testkey=hello"];
[__request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
[NSURLConnection sendSynchronousRequest:__request returningResponse:nil error:nil];
我的应用引擎处理程序:
class TestParameter(webapp.RequestHandler):
def post(self):
logging.debug(self.request.get("testkey"))
self.response.out.write(self.request.get("testkey"))
print self.request.get("testkey")
def get(self):
logging.debug("get")
logging.debug(self.request.get("testkey"))
self.response.out.write(self.request.get("testkey"))
GAE 日志中的输出显示“get”代码路径不正确。
知道为什么 POST 请求会以 GET 形式进入 GAE 吗?我错过了 GAE 中的某些配置吗?
谢谢!
【问题讨论】:
-
是否有可能对 POST 的响应重定向到 GET?
-
不确定这将如何发生或如何测试?我没有指示它这样做。有没有办法测试?
-
一种方法是使用网络上的数据包嗅探器来查看真正发生了什么。这种技术解决了所有可能使问题复杂化的应用程序级别的东西。
-
呃。是的,看着查尔斯。如果您在非安全尝试中遇到 POST 请求,它会将 302 重定向发送回 https 版本。这可能会作为获取请求被重新发送。
标签: ios google-app-engine post get