views:

143

answers:

2

Is it possible to send text from an xcode input and have the data sent through a php function?

A: 

You can use this to post data from your xCode app to a web server.

http://allseeing-i.com/ASIHTTPRequest/

Brad
A: 

If you actually want to do this using simple Objective-C (Foundation) classes, you should use NSURLConnection. Example:

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");
Cappuccino Plus Plus