NSString *post = [NSString stringWithFormat:@"email=%@",_benimEmail];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURLURLWithString:@"http://localhost:8888/iphone/msg.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error; NSURLResponse *response;
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *veri = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",veri);
上面的代码在单击按钮时运行,它将查询 Web 服务。
现在,当我单击按钮时,应用程序会冻结一段时间。我怎样才能防止这种情况发生?