iphone - 在 Google App Engine Python API 中获取原始发布数据

标签 iphone python google-app-engine post 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];

服务器端代码是:

class userResult(webapp.RequestHandler):
def __init__(self):
    self.qNo = 1
def post(self):
    return self.request.get('json')

最佳答案

self.request.get('content') 将为您提供以参数名称“content”发送的数据。如果您想要原始发布数据,请使用 self.request.body

关于iphone - 在 Google App Engine Python API 中获取原始发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2251584/

相关文章:

python - 如何在GAE上过滤图像?

iphone - iPhone 或 iPod Touch 可以与同一房间内的其他设备通信吗?

iphone - 隐藏文本字段的键盘并显示日期选择器

iphone - 如何知道适合固定大小的 UILabel 的 NSString 长度?

iphone - iAd 在模拟器上有效,但在设备上无效

python - 如何将一个数字的格式复制到另一个数字?

python - appengine python 关闭 Hook

python - OpenCV 中的 Lucas-Kanade 光流对我不起作用

python - 给定掩码标记边界

google-app-engine - dev/urandom-strerror : file not accessible