msk*_*msk 3 python iphone post google-app-engine request
我正在尝试使用self.request.get('content')将原始数据作为帖子发送到Google App引擎,但是徒劳无功.它返回空.我确信数据是从客户端发送的,因为我检查了另一个简单的服务器代码.
知道我做错了什么吗?我在客户端使用以下代码生成POST调用(objective-c/cocoa-touch)
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];
Run Code Online (Sandbox Code Playgroud)
服务器端代码是:
class userResult(webapp.RequestHandler):
def __init__(self):
self.qNo = 1
def post(self):
return self.request.get('json')
Run Code Online (Sandbox Code Playgroud)