2010-09-19 80 views

回答

3

如果你真的想這樣做,使用簡單的Objective-C(基金會)班,你應該使用NSURLConnection的。例如:

NSString * post = [[NSString alloc] initWithFormat:@"&myvariable=%@", myString]; 
NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]; 
NSString * postLength = [NSString stringWithFormat:@"%d",[postData length]]; 
NSMutableURLRequest * request = [[[NSMutableURLRequest alloc] init] autorelease]; 
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.yoursite.com/file.php"]]]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:postData]; 
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

if (conn) NSLog(@"Connection Successful");