0

我已经尝试了很多方法,但我仍然在服务器端得到一个空数组。

这是我的代码:

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];
4

1 回答 1

0
    NSURL * serviceUrl = [NSURL URLWithString:@"weblink"];
    NSMutableURLRequest * serviceRequest = [NSMutableURLRequest requestWithURL:serviceUrl];
    [serviceRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
    //[serviceRequest setValue:txtTitle.text forHTTPHeaderField:@"title"];
    [serviceRequest setHTTPMethod:@"POST"];
    [serviceRequest setHTTPBody:[xmlString dataUsingEncoding:NSASCIIStringEncoding]];
    [serviceRequest setValue:[NSString stringWithFormat:@"%d",[xmlString length]] forHTTPHeaderField:@"Content-Length"];
    NSURLResponse * serviceResponse;
    NSError * serviceError;

    NSData *responseData = [NSURLConnection sendSynchronousRequest:serviceRequest returningResponse:&serviceResponse error:&serviceError];
    NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease];
于 2012-07-09T13:41:57.637 回答