0
嗨,我想知道我可以如何使用NSURLConnection或JSon將數據從4 UITextField發送到網站上的PHP腳本。無論如何,我怎樣才能做到這一點?通過NSURLConnection或JSon將數據從UITextField發送到PHP腳本
在此先感謝!
嗨,我想知道我可以如何使用NSURLConnection或JSon將數據從4 UITextField發送到網站上的PHP腳本。無論如何,我怎樣才能做到這一點?通過NSURLConnection或JSon將數據從UITextField發送到PHP腳本
在此先感謝!
最簡單的方法(同步)
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);
}
哪部分是你不確定?從文本字段中提取數據或將數據發送到服務器? – Devraj