我需要发送一个ASI http请求,一个帖子表单,
当我检查身体的要求时,它似乎是空的, 如何检查身体是什么?,为什么它是空的?
谢谢!
- (void)sendUnsentEntries {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (!sendingEntries) {
sendingEntries = YES;
Reachability *reachability = [Reachability reachabilityForInternetConnection];
BOOL errorsSending = NO;
NSInteger unsentCount = 0;
if ([Client unsubmittedCount] > 0 && [reachability isReachable]) {
NSString *host = [self apiHost];
for (Client* clientToSend in [Client allUnsubmitted]) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", host]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
request.requestMethod = @"POST";
[request setPostValue:clientToSend.name forKey:@"name"];
[request setPostValue:clientToSend.territory forKey:@"territory"];
NSLog(@"name:: %@", clientToSend.name);
//LOGING THE FOR THE REQUEST
NSString *requ = [[[NSString alloc] initWithData:[request postBody] encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"request body: %@", requ);
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *responseString = [request responseString];
NSLog(@"response :::%@",responseString);
if ([responseString isEqualToString:@"true"]) {
clientToSend.submitted = [NSNumber numberWithBool:YES];
}
} else {
NSLog(@"error: %@", [error description]);
}
[[self managedObjectContext] save:nil];
}
unsentCount += [Client unsubmittedCount];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:unsentCount];
if (errorsSending && showSendingErrors) {
}
}
sendingEntries = NO;
[pool release];
}
}
所以我得到了我的
记录:: request body:
空响应,
这是记录表单正文的方法吗?
谢谢!
答案 0 :(得分:1)
在将表单提交给服务器之前,不会构建帖子正文。
您有两种选择:
[request startSynchronous];
[request buildPostBody];
醇>