Xcode: Easiest Way To Send Data From iOS TextField For Example To A Remote Database

风格不统一 提交于 2019-12-01 01:38:35

You can just gather the data from a native form, then use a NSURLRequest / NSURLConnection to send the data to your php server page.

//Example form with one php variable only. Use get URL argument notation to add more args.
NSString *rawStr = [NSString stringWithFormat:@"var=%@",textBox.text];
NSData *data = [rawStr dataUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:@"http://myurl.com/script.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];

NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!