我有一個NSURLConnection,它是服務器的一個帖子,但我希望它返回一些小數據,無論它是否成功。NSURLConnection POST也會調用同一個URL的GET
-(void)submitPost:(NSString *)xml
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[service generateURL]];
NSString *result = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)xml, NULL, CFSTR("?=&+"), kCFStringEncodingUTF8);
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[result dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if(theConnection)
{
NSLog(@"Connection success");
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[theConnection retain];
failed = NO;
}
else
{
NSLog(@"Connection failed");
}
}
的問題是,它不僅發個帖子的網址,它也將GET和GET響應返回的數據...我有點糊塗了。我檢查了我的wireshark輸出,這絕對是一個帖子和一個get。
你們認爲什麼?
由於您已經將它連接起來,似乎沒有必要保留連接。 – ma11hew28 2011-05-30 19:19:35