我在这里有一个小问题。我正在使用表单进行登录,将字符串发送到php,最后回答“错误”或“确定”。
但是,我需要php返回比它更多的东西,比如名字等,我想在标签中显示这个名字。那么,为此,我需要一个数组,对吗?
那么,我该怎么做呢?
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL:
[NSURL URLWithString:@"http://localhost/dev/mcomm/login.php"]];
[request setHTTPMethod:@"POST"];
NSString *postString = [[NSString alloc] initWithFormat:@"email=%@&pass=%@", email.text, senha.text];
[request setValue:[NSString
stringWithFormat:@"%d", [postString length]]
forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[postString
dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc]
initWithRequest:request delegate:self];
//get response
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
NSLog(@"Response: %@", result);
}
谢谢!