我正在尝试通过 iPhone 应用程序的 POST 将参数发布到 Google App Engine 上的 Java servlet。当服务器在本地运行时,这可以正常工作,但是当它部署到 App Engine 时,参数始终为空。为什么?
应用引擎代码:
String facebookFriendTokens = (String) req.getParameter("facebookFriendTokens");
//running on localhost, facebookFriendTokens works fine, deployed to GAE it's always null
log.warning("Facebook friends = " + facebookFriendTokens);
手机代码:
NSString *urlString = [NSString stringWithFormat:@"%@/new_huddle?access_token=%@", SERVER_URL, [defaults objectForKey:@"FBAccessTokenKey"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
NSString *postString = [NSString stringWithFormat:@"facebookFriendTokens=%@&eventDate=%@&placesTokens=%@&name=%@", encodedFriendTokens, encodedDateString, placesQueryStringParm, encodedNameString];
[encodedNameString release];
[encodedDateString release];
[encodedFriendTokens release];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue: ...
如果我将 request.getInputStream() 处理为字符串并打印它,它会按预期显示。我应该那样解析字符串吗?
另外,我确实有一个 servlet 过滤器,这可能会修改请求吗?
我想知道服务器是否正在发出重定向,因此我在后续请求中丢失了所有正文数据。我现在正在本地测试这个。