我已经尝试了很多方法,但我仍然在服务器端得到一个空数组。
这是我的代码:
NSString *urlString = [[NSString alloc] initWithFormat:@"%@/test.php", APP_WEBSITE_URL];
NSURL *requestURL = [NSURL URLWithString:urlString];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[requestObj setHTTPMethod:@"POST"];
[requestObj setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
NSInteger tmpCount = [strawPollDetailItem.selectionsArray count];
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"<SUBMITTED>"] dataUsingEncoding:NSUTF8StringEncoding]];
for (int i=0; i<tmpCount; i++) {
NSInteger selectedID = [strawPollDetailItem.selectionsArray objectAtIndex:i];
[postBody appendData:[[NSString stringWithFormat:@"<OPTIONID>%@</OPTIONID>", selectedID] dataUsingEncoding:NSUTF8StringEncoding]];
}
[postBody appendData:[[NSString stringWithFormat:@"</SUBMITTED>"] dataUsingEncoding:NSUTF8StringEncoding]];
[requestObj setHTTPBody:postBody];
[[NSURLConnection alloc] initWithRequest:requestObj delegate:self];