我正在使用Google云端点与数据存储。当我通过Android & iOS方法通过POST方法传递数据时,它将被保存在具有空记录的数据存储中。即请求正常工作,但我发送数据的方式是错误的。请帮助我。 对于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* [email protected]"";
strRequest =[[NSString alloc] initWithFormat:@"displayEmail=%@&displayName=%@",@"[email protected]",@"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];
如何你发现请求是空白的吗?我们需要更多的代码。 – Poles
我编辑我的代码..请看看,让我知道 –
代码看起来不错。但是如何说明请求是空白的。 – Poles