如何在web服务上解开uitextfield数据

我有login屏幕公司注册,我想发布所有uitextfield数据上点击button上的web服务。

公司注册形象

这是我点击button的代码

- (IBAction)Register:(id)sender { if (_CompanyName.text.length <=0) { NSLog(@"enter company name"); UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter Company Name" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil]; [message setAlertViewStyle:UIAlertViewStyleDefault]; [message show]; } 

我是那种活动的初学者,所以如果有人知道的话请帮忙,谢谢。

下面是非常简单的发布数据到服务器编码

 - (IBAction)actionRegister:(id)sender { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:strYourURL]]; [request setHTTPMethod:@"POST"]; //Check The Value what we entered in textField NSLog(@"the company name is:%@",txtFieldCompanyName.text); NSLog(@"the email is:%@",txtFieldEmail.text); NSLog(@"the password is:%@",txtFieldPassword.text); NSLog(@"the password again is:%@",txtFieldPasswordAgain.text); //Pass The String to server NSString *strParameters =[NSString stringWithFormat:@"comapny_name=%@&email=%@&password=%@&password_again=%@",txtFieldCompanyName.text,txtFieldEmail.text,txtFieldPassword.text,txtFieldPasswordAgain.text,nil]; //Check The Value what we passed NSLog(@"the data Details is =%@", strParameters); //Convert the String to Data NSData *data1 = [strParameters dataUsingEncoding:NSUTF8StringEncoding]; //Apply the data to the body [request setHTTPBody:data1]; //Create the response and Error NSError *err; NSURLResponse *response; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding]; //This is for Response NSLog(@"got response==%@", resSrt); if(resSrt) { NSLog(@"got response"); } else { NSLog(@"faield to connect"); } } 

使用AFNetworking类这里是一个链接

https://github.com/AFNetworking/AFNetworking

http://www.raywenderlich.com/59255/afnetworking-2-0-tutorial

还有一些你会从这个教程中得到的代码

 - (IBAction)registerButtonTapped:(id)sender { // 1 NSString *string = [NSString stringWithFormat:@"www.yourwebapiurl.php?format=json&username=%@", userNameTextField.text];//and so on NSURL *url = [NSURL URLWithString:string]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; // 2 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { // 3 NSDictionary *responseDict = (NSDictionary *)responseObject; NSLog(@"You have got the response "); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { // 4 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alertView show]; }]; // 5 [operation start]; } 

这将帮助。谢谢