我试图使用self.request.get('content')获取原始数据作为发布到Google App引擎,但徒劳无功。它返回空。我确信数据正在从客户端发送,因此我使用另一个简单的服务器代码进行了检查。在Google App Engine中获取原始发布数据Python API
任何想法我做错了什么?我使用在客户端产生的POST调用(Objective-C的/可可触摸)下面的代码
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableDictionary *diction = [[NSMutableDictionary alloc] init];
NSString *tempcurrentQuestion = [[NSString alloc] initWithFormat:@"%d", (questionNo+1)];
NSString *tempansweredOption = [[NSString alloc] initWithFormat:@"%d", (answeredOption)];
[diction setValue:tempcurrentQuestion forKey:@"questionNo"];
[diction setValue:tempansweredOption forKey:@"answeredOption"];
[diction setValue:country forKey:@"country"];
[array addObject:diction];
NSString *post1 = [[CJSONSerializer serializer] serializeObject:array];
NSString *post = [NSString stringWithFormat:@"json=%@", post1];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSLog(@"Length: %d", [postData length]);
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://localhost:8080/userResult/"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
questionsFlag = FALSE;
[[NSURLConnection alloc] initWithRequest:request delegate:self];
服务器端代码:
class userResult(webapp.RequestHandler):
def __init__(self):
self.qNo = 1
def post(self):
return self.request.get('json')
如果您发布生成请求的HTML表单以及正在接收POST的AppEngine RequestHandler,我们可能会继续做下去。 – 2010-02-12 13:48:19