2010-09-19 54 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");