我正在使用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