ios - 通过 iOS 向 Google Cloud 端点发送数据时请求为空

标签 ios google-cloud-datastore google-cloud-endpoints

我正在使用数据存储区开发 Google 云端点。当我使用方法 POST 通过 Android 和 iOS 传递数据时,它会以空记录保存在数据存储中。即请求正常工作,但我发送数据的方式是错误的。请帮我这个。 对于iOS,代码如下:

NSDictionary *headers = @{ @"content-type": @"application/json",
                           @"cache-control": @"no-cache",
                           @"postman-token": @"404012ff-722e-c5d8-48db-fa7fb3260841"};
NSLog(@"header %@",headers);
request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"enter url here..."]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
NSString*  strRequest=@"";
strRequest =[[NSString alloc] initWithFormat:@"displayEmail=%@&displayName=%@",@"sonal@gmail.com",@"sonal"];
NSLog(@"url is %@  parameter = %@", request , strRequest);
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [strRequest dataUsingEncoding:NSUTF8StringEncoding]];
[request setAllHTTPHeaderFields:headers];
NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                NSString *responseBody = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                                                NSLog(@"responce Body===>%@",responseBody);
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"responce%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

最佳答案

关于ios - 通过 iOS 向 Google Cloud 端点发送数据时请求为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40910452/

相关文章:

ios - 在 View Controller 之间切换(同时使用 VC)

java - Google App Engine 如何跟踪 httpsession 销毁

java - 在自定义域 URL 地址上公开 appengine 云端点 api

python - GAE 数据存储在 python api 中预先加载

java - 为 Cloud Endpoints 类生成 API 元数据失败

java - 从 Java 删除 Google Cloud Bucket 中 'folder' 或带有前缀的所有文件

UITextView 中的 iOS6 音频标签

ios - UITextField 未在函数中注册任何文本长度

ios - Realm Relation如何实现

java - 如何使用 mapreduce 批量更新满足查询的数据存储实体?