简体   繁体   English

通过NSURLConnection或JSon将UITextField中的数据发送到PHP脚本

[英]Sending Data from UITextField to PHP script via NSURLConnection or JSon

Hi I would like to know how I can go about sending data from 4 UITextField's to a PHP script on a website using NSURLConnection or JSon. 嗨,我想知道如何使用NSURLConnection或JSon将4个UITextField的数据发送到网站上的PHP脚本。 Whatever is easier, how can I do this exactly? 哪个更容易,我该怎么做呢?

Thanks in advance! 提前致谢!

Easiest way (synchronous) 最简单的方法(同步)

NSString strForTextField1 = textField1.text;
NSString strForTextField2 = textField1.text;
NSString strForTextField3 = textField1.text;
NSString strForTextField4 = textField1.text;

//Build the request
NSString *stringOfRequest = [NSString stringWithFormat:@"www.yourserver.com?var1=%@&var2=%@&var3=%@&var4=%@", strForTextField1, strForTextField2, strForTextField3, strForTextField4];
NSURL *url = [NSURL URLWithString:stringOfRequest];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSURLResponse *response;
NSError *error;
//send it synchronous
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

if(!error)
{
    //log response
    NSLog(@"Response from server = %@", responseString);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM