Is it possible to send text from an xcode input and have the data sent through a php function?
2 Answers
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");
Comments
You can use this to post data from your xCode app to a web server.
1 Comment
Mike Owens
The library is no longer worked on and the webpage recommends that you use something else.