I’m attempting to post parameters to a Java servlet on Google App Engine via POST from an iPhone app. When the server is running locally, this works fine, but when it is deployed to App Engine, the parameters are always null. Why?
App Engine code:
String facebookFriendTokens = (String) req.getParameter("facebookFriendTokens");
//running on localhost, facebookFriendTokens works fine, deployed to GAE it's always null
log.warning("Facebook friends = " + facebookFriendTokens);
iPhone code:
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: ...
If I process the request.getInputStream() into a string and print it, it’s appears as expected. Should I just parse the string that way?
Also, I do have a servlet filter in place, could that possibly be modifying the request?
I’m wondering if the server is issuing a redirect and I’m thus losing all the body data in the subsequent request. I’m working to test this locally now.
The problem ended up being a ghost/hidden redirect that the GAE AppSpot server was doing when requests were being made to http rather than https. Since I was not manually handling creating/modifying the new request upon the redirect, the body and post parameters were being lost, and thus never able to be retrieved by the server.
Simply changing the url from http to https on the client fixed the problem.